Coder Social home page Coder Social logo

cowboy_fcgi's Introduction

cowboy_fcgi

FastCGI handler for Cowboy web server - allows PHP scripts to run along side your Erlang web applications via php-fpm.

This is a fork of extend/cowboy_fcgi which is no longer maintained in that repo. I have updated the code to support latest Cowboy 2 stable version.

status

It is currently tested against stable Cowboy version 2 and PHP 7 (it should also work with PHP 5).

getting started

requirements

  • erlang (19.0 or newer)
  • GNU make (or rebar3)
  • php-fpm executable in path

quick start

  • clone this repo
  • cd cowboy_fcgi/examples/cowboy_php_hello
  • make run

This should land you on a console of a running application.

Use a web client or a browser to visit

http://localhost:33080/hello.php

You should see a simple response from hello.php script. Get more details in the example's README.

docs

Docs coming soon... for now see the examples.

faq

what is php-fpm?

PHP FPM is a FastCGI Process Manager for PHP. It is used by web servers such as Nginx and Apache to integrate with PHP.

cowboy_fcgi's People

Contributors

essen avatar nox avatar unix1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cowboy_fcgi's Issues

Move to erlang.mk

While remaining compatible with rebar3 per #3 move Makefile to use erlang.mk.

curl http2 request results in invalid HTTP header error

Steps to repro:

  • make run the example
  • curl --http2 -v http://localhost:33080/hello.php

Expected result: response from hello.php

Actual result:

...
http2 error: Invalid HTTP header field was received: frame type: 1, stream: 1, name: [Content-Type], value: [text/plain;charset=UTF-8]
...

Sub-directory path support is broken

Steps to repro:

  • make run the example
  • create a foo/bar.php file with some PHP content under priv/www directory
  • make an HTTP request to /foo/bar.php

Expected result: bar.php executes and its response is received by the client.

Actual result: Cowboy 404 response.

Update for rebar3

Requirements:

  • it should still compile with legacy rebar
  • it should be fully compatible with rebar3

Crash after thousands of requests

While testing the fcgi client on Cowboy 2.0.0 using siege, after making some thousands of requests cowboy/ranch will report a crash such as this:

Ranch listener fcgi, connection process <0.830.4>,
stream 1 had its request process <0.842.4> exit with reason {case_clause,undefined}
and stacktrace
[
  {cowboy_http_fcgi,init,2,[{file,"src/cowboy_http_fcgi.erl"},{line,61}]},
  {cowboy_handler,execute,2, [{file,"src/cowboy_handler.erl"},{line,37}]},
  {cowboy_stream_h,execute,3, [{file,"src/cowboy_stream_h.erl"},{line,205}]}
  {cowboy_stream_h,request_process,3,[{file,"src/cowboy_stream_h.erl"},{line,184}]},
  {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,247}]}
]

For few seconds the test "hangs" waiting for responses. The requests eventually time out after exactly 15 seconds with 504 (gateway timeout) responses. After this the system recovers and requests may continue.

Line 61-62 in cowboy_http_fcgi are

State = case whereis(Name) of
  Server when is_pid(Server) ->

This means whereis is probably not finding the locally registered process anymore. This means the process has likely crashed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.