Quantcast

Serve PHP/Python scripts behind Erlang

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Serve PHP/Python scripts behind Erlang

Frank Muller
Hi guys

What’s the most efficient way to run PHP (Python) scripts behind Erlang?

I would like to receive HTTP requests in Cowboy and forward them to a PHP/Python backend.

Get the response back from the backend and forward it to the client.

Thanks in advance.
/Frank

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Serve PHP/Python scripts behind Erlang

Loïc Hoguin-3
The typical setup uses fastcgi: https://en.wikipedia.org/wiki/FastCGI

There was an early attempt by Anthony at
https://github.com/extend/ex_fcgi - not sure how much of it still works,
but probably worth salvaging.

On 03/13/2017 06:09 PM, Frank Muller wrote:

> Hi guys
>
> What’s the most efficient way to run PHP (Python) scripts behind Erlang?
>
> I would like to receive HTTP requests in Cowboy and forward them to a
> PHP/Python backend.
>
> Get the response back from the backend and forward it to the client.
>
> Thanks in advance.
> /Frank
>
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
>

--
Loïc Hoguin
https://ninenines.eu
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Serve PHP/Python scripts behind Erlang

Frank Muller
Thanks Loïc, that was the first lib I found. But it seems to be outdated. 

I'll will dig into the FastCGI spec soon.

Anyone else?

/Frank

The typical setup uses fastcgi: https://en.wikipedia.org/wiki/FastCGI

There was an early attempt by Anthony at
https://github.com/extend/ex_fcgi - not sure how much of it still works,
but probably worth salvaging.

On 03/13/2017 06:09 PM, Frank Muller wrote:
> Hi guys
>
> What’s the most efficient way to run PHP (Python) scripts behind Erlang?
>
> I would like to receive HTTP requests in Cowboy and forward them to a
> PHP/Python backend.
>
> Get the response back from the backend and forward it to the client.
>
> Thanks in advance.
> /Frank
>
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
>

--
Loïc Hoguin
https://ninenines.eu

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Serve PHP/Python scripts behind Erlang

Max Lapshin-2
we are running python flask backend behind flussonic (written in erlang).

we launch small launcher and then proxy http requests.

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Serve PHP/Python scripts behind Erlang

Nathaniel Waisbrot
In reply to this post by Frank Muller
It depends on what you mean by "efficient" :-) Some methods that I've worked with (Python only)

- Python uses Flask+Gunicorn to serve requests, Erlang makes HTTP calls to it
  You get to customize the request as much as you want in Erlang, the coupling is loose, it's easy to do black-box tests on the Python service alone
- Python uses Flask+Gunicorn to serve requests, Nginx reverse-proxies to Python and to Erlang, P&E don't talk to each other
  Nginx is good at forwarding connections, the coupling is loose, it's easy to do black-box tests on either sub-service alone
- Erlang calls Python through ErlPort (http://erlport.org/)
  Faster than a network connection, tighter coupling, you manage queueing and pooling yourself



On Mar 13, 2017, at 1:47 PM, Frank Muller <[hidden email]> wrote:

Thanks Loïc, that was the first lib I found. But it seems to be outdated. 

I'll will dig into the FastCGI spec soon.

Anyone else?

/Frank

The typical setup uses fastcgi: https://en.wikipedia.org/wiki/FastCGI

There was an early attempt by Anthony at
https://github.com/extend/ex_fcgi - not sure how much of it still works,
but probably worth salvaging.

On 03/13/2017 06:09 PM, Frank Muller wrote:
> Hi guys
>
> What’s the most efficient way to run PHP (Python) scripts behind Erlang?
>
> I would like to receive HTTP requests in Cowboy and forward them to a
> PHP/Python backend.
>
> Get the response back from the backend and forward it to the client.
>
> Thanks in advance.
> /Frank
>
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
>

--
Loïc Hoguin
https://ninenines.eu
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Serve PHP/Python scripts behind Erlang

Michael Truog
In reply to this post by Frank Muller
On 03/13/2017 10:47 AM, Frank Muller wrote:
Thanks Loïc, that was the first lib I found. But it seems to be outdated. 

I'll will dig into the FastCGI spec soon.

Anyone else?

If you are using PHP and/or Python code as services that are always running for the sake of efficiency and you want to maximize throughput (avoiding an Erlang port of cnode being a bottleneck), CloudI can provide service messaging and be an application server for the PHP/Python with Erlang.  The cloudi_service_http_cowboy and cloudi_service_http_elli provide integration for making HTTP requests CloudI service requests.  There is some justification at http://cloudi.org/faq.html#4_Erlang and examples at http://cloudi.org/tutorials.html#cloudi_examples .


/Frank

The typical setup uses fastcgi: https://en.wikipedia.org/wiki/FastCGI

There was an early attempt by Anthony at
https://github.com/extend/ex_fcgi - not sure how much of it still works,
but probably worth salvaging.

On 03/13/2017 06:09 PM, Frank Muller wrote:
> Hi guys
>
> What’s the most efficient way to run PHP (Python) scripts behind Erlang?
>
> I would like to receive HTTP requests in Cowboy and forward them to a
> PHP/Python backend.
>
> Get the response back from the backend and forward it to the client.
>
> Thanks in advance.
> /Frank
>
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
>

--
Loïc Hoguin
https://ninenines.eu


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Serve PHP/Python scripts behind Erlang

Nuku Ameyibor
In reply to this post by Frank Muller
Yaws web server also has this .
http://yaws.hyber.org/cgi.yaws .

From: [hidden email]
Sent: ‎3/‎13/‎2017 5:47 PM
To: [hidden email]; [hidden email]
Subject: Re: [erlang-questions] Serve PHP/Python scripts behind Erlang

Thanks Loïc, that was the first lib I found. But it seems to be outdated. 

I'll will dig into the FastCGI spec soon.

Anyone else?

/Frank

The typical setup uses fastcgi: https://en.wikipedia.org/wiki/FastCGI

There was an early attempt by Anthony at
https://github.com/extend/ex_fcgi - not sure how much of it still works,
but probably worth salvaging.

On 03/13/2017 06:09 PM, Frank Muller wrote:
> Hi guys
>
> What’s the most efficient way to run PHP (Python) scripts behind Erlang?
>
> I would like to receive HTTP requests in Cowboy and forward them to a
> PHP/Python backend.
>
> Get the response back from the backend and forward it to the client.
>
> Thanks in advance.
> /Frank
>
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
>

--
Loïc Hoguin
https://ninenines.eu

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Serve PHP/Python scripts behind Erlang

Frank Muller
In reply to this post by Max Lapshin-2
Hi Max,

Can you please elaborate a bit more?

How do you launch these PHP instances?
Which protocole do you use between Erlang and PHP?

/Frank

<[hidden email]> a écrit :
we are running python flask backend behind flussonic (written in erlang).

we launch small launcher and then proxy http requests.

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Serve PHP/Python scripts behind Erlang

Frank Muller
In reply to this post by Michael Truog
Hi Michael,

Never heard about CloudI. Sounds very interesting.
 I'll give it try. 

/Frank

<[hidden email]> a écrit :
On 03/13/2017 10:47 AM, Frank Muller wrote:
Thanks Loïc, that was the first lib I found. But it seems to be outdated. 

I'll will dig into the FastCGI spec soon.

Anyone else?

If you are using PHP and/or Python code as services that are always running for the sake of efficiency and you want to maximize throughput (avoiding an Erlang port of cnode being a bottleneck), CloudI can provide service messaging and be an application server for the PHP/Python with Erlang.  The cloudi_service_http_cowboy and cloudi_service_http_elli provide integration for making HTTP requests CloudI service requests.  There is some justification at http://cloudi.org/faq.html#4_Erlang and examples at http://cloudi.org/tutorials.html#cloudi_examples .



/Frank

The typical setup uses fastcgi: https://en.wikipedia.org/wiki/FastCGI

There was an early attempt by Anthony at
https://github.com/extend/ex_fcgi - not sure how much of it still works,
but probably worth salvaging.

On 03/13/2017 06:09 PM, Frank Muller wrote:
> Hi guys
>
> What’s the most efficient way to run PHP (Python) scripts behind Erlang?
>
> I would like to receive HTTP requests in Cowboy and forward them to a
> PHP/Python backend.
>
> Get the response back from the backend and forward it to the client.
>
> Thanks in advance.
> /Frank
>
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
>

--
Loïc Hoguin
https://ninenines.eu


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Serve PHP/Python scripts behind Erlang

Frank Muller
In reply to this post by Nathaniel Waisbrot
Nathaniel,

Can the erlport solution scale?

/Frank

<[hidden email]> a écrit :
It depends on what you mean by "efficient" :-) Some methods that I've worked with (Python only)

- Python uses Flask+Gunicorn to serve requests, Erlang makes HTTP calls to it
  You get to customize the request as much as you want in Erlang, the coupling is loose, it's easy to do black-box tests on the Python service alone
- Python uses Flask+Gunicorn to serve requests, Nginx reverse-proxies to Python and to Erlang, P&E don't talk to each other
  Nginx is good at forwarding connections, the coupling is loose, it's easy to do black-box tests on either sub-service alone
- Erlang calls Python through ErlPort (http://erlport.org/)
  Faster than a network connection, tighter coupling, you manage queueing and pooling yourself



On Mar 13, 2017, at 1:47 PM, Frank Muller <[hidden email]> wrote:

Thanks Loïc, that was the first lib I found. But it seems to be outdated. 

I'll will dig into the FastCGI spec soon.

Anyone else?

/Frank

The typical setup uses fastcgi: https://en.wikipedia.org/wiki/FastCGI

There was an early attempt by Anthony at
https://github.com/extend/ex_fcgi - not sure how much of it still works,
but probably worth salvaging.

On 03/13/2017 06:09 PM, Frank Muller wrote:
> Hi guys
>
> What’s the most efficient way to run PHP (Python) scripts behind Erlang?
>
> I would like to receive HTTP requests in Cowboy and forward them to a
> PHP/Python backend.
>
> Get the response back from the backend and forward it to the client.
>
> Thanks in advance.
> /Frank
>
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
>

--
Loïc Hoguin
https://ninenines.eu
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Serve PHP/Python scripts behind Erlang

Max Lapshin-2
In reply to this post by Frank Muller
I launch via  erlang:open_port and struggle a lot trying to make children stop when erlang server dies: it is not easy.

then child ruby/python starts listening http port and erlang forwards all requests from wide web to launched http server.

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Serve PHP/Python scripts behind Erlang

Antonio SJ Musumeci
Max,

If you control the child code it shouldn't be too difficult to manage the exiting of children when erlang dies. Even if you don't control it you can create a little shim that does.

Few things you can mix and match:

1) On Linux you can use prctl with PR_SET_PDEATHSIG
2) look at parent pid on occasion. If it becomes 1 (or not what it was at start, slight race condition but you can set the value as an envvar) then you know your parent is dead.
3) In a shim use the old pipe trick (http://skarnet.org/software/s6/s6-fghack.html). If the breaks then the other side is gone.

If using the shim approach you can then kill the child when the shim detects the parent's death.

On Mon, Mar 13, 2017 at 3:53 PM, Max Lapshin <[hidden email]> wrote:
I launch via  erlang:open_port and struggle a lot trying to make children stop when erlang server dies: it is not easy.

then child ruby/python starts listening http port and erlang forwards all requests from wide web to launched http server.

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Serve PHP/Python scripts behind Erlang

Dave Cottlehuber-5
> On Mon, Mar 13, 2017 at 3:53 PM, Max Lapshin <[hidden email]>
> wrote:
>
> > I launch via  erlang:open_port and struggle a lot trying to make children
> > stop when erlang server dies: it is not easy.

https://github.com/saleyn/erlexec

A+
Dave
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Serve PHP/Python scripts behind Erlang

Raghav Karol
In reply to this post by Frank Muller
Hi Frank, 

It might be worthwhile to look into Cowboy + RabbitMQ RPC. I have seen this pattern used in production, (<10 ms latency in AWS).

Cowboy  handles web requests and makes AMQP RPC calls to a PHP (Python) service. You get all the benefits (and drawbacks) of having a queue of work, e.g., being able to start multiple workers dynamically to scale up and down.

--
Raghav

On Mon, Mar 13, 2017 at 6:09 PM, Frank Muller <[hidden email]> wrote:
Hi guys

What’s the most efficient way to run PHP (Python) scripts behind Erlang?

I would like to receive HTTP requests in Cowboy and forward them to a PHP/Python backend.

Get the response back from the backend and forward it to the client.

Thanks in advance.
/Frank

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions




--
Raghav

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Serve PHP/Python scripts behind Erlang

Frank Muller
Thank you guys for all these links. 
Still studying them. 

/Frank

<[hidden email]> wrote :
Hi Frank, 

It might be worthwhile to look into Cowboy + RabbitMQ RPC. I have seen this pattern used in production, (<10 ms latency in AWS).

Cowboy  handles web requests and makes AMQP RPC calls to a PHP (Python) service. You get all the benefits (and drawbacks) of having a queue of work, e.g., being able to start multiple workers dynamically to scale up and down.

--
Raghav

On Mon, Mar 13, 2017 at 6:09 PM, Frank Muller <[hidden email]> wrote:
Hi guys

What’s the most efficient way to run PHP (Python) scripts behind Erlang?

I would like to receive HTTP requests in Cowboy and forward them to a PHP/Python backend.

Get the response back from the backend and forward it to the client.

Thanks in advance.
/Frank

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions




--
Raghav

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Loading...