Giter VIP home page Giter VIP logo

fastcgi's People

Contributors

jhs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

fastcgi's Issues

TCP Support

Adding TCP sockets support would allow to use more FastCGI modules.

Add request handler method

I would like to suggest adding a requestHandler object to export which would allow you to mount the application on any compatible request handler. My implementation used a sort of promise object and basically copied the httpd method. It seems like it shouldn't have to be a promise object, but this is how it ended up. It could also be sent in the callback and then you would just call it in your code.

function getHandler(port, host, socket_path, callback){
  var promise = { requestHandler: function(req, res){ throw new Exception("Promised object not ready yet. Check the ready property"); }, ready: false };
  connect_fcgi(socket_path, 0, function(er, socket) {
    if(er)
      return callback(er)

    fcgi_get_values(socket, function(er, values) {
      if(er)
        return callback(er)

      values.FCGI_MPXS_CONNS = values.FCGI_MPXS_CONNS || 0
      LOG.info('FCGI values: %j', values)

      promise.requestHandler = fcgi_handler(port, host, values, socket, socket_path);
      promise.ready = true;
      return callback(null)
    })
  })
}

unhandled error event (most likely node v0.10.x related)

When using this in combination with graphite, the following error is received sporadically when trying to load the graphite web interface.

Get FastCGI values
Listening for FastCGI values
FCGI values: {"FCGI_MAX_CONNS":1024,"FCGI_MAX_REQS":1024,"FCGI_MPXS_CONNS":0}
Listening on 0.0.0.0:24093
GET / 200
GET /browser/header/ 200
GET /composer/? 200
STDERR: No handlers could be found for logger "rendering"
STDERR:
GET /render 200
GET /render/?width=586&height=308&_salt=1372100547.596 200
GET /favicon.ico 200
GET / 200
GET /browser/header/ 200

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: write after end
    at writeAfterEnd (_stream_writable.js:125:12)
    at Socket.Writable.write (_stream_writable.js:170:5)
    at Socket.write (net.js:596:40)
    at process_request (/home/ubuntu/hosting/manager/node_modules/fastcgi/fastcgi.js:207:12)
    at Server.on_request (/home/ubuntu/hosting/manager/node_modules/fastcgi/fastcgi.js:145:5)
    at Server.EventEmitter.emit (events.js:98:17)
    at HTTPParser.parser.onIncoming (http.js:2012:12)
    at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:119:23)
    at Socket.socket.ondata (http.js:1902:22)
    at TCP.onread (net.js:510:27)

@jhs Through my investigation I believe it comes into play due to there not being an error handler here and the fact that streams2 must have changed the actual stream. Still digging in, just wanted to get this documented.

Unable to run nodejs fastcgi

Hi,

I tried to use nodejs with fastcgi but failed to execute it. Any comments? Thanks

root@ubuntu12:/tmp# ./node_modules/fastcgi/cli.js --port=1234 --socket=/tmp/php-fpm.socket
Sending http requests to /tmp/php-fpm.socket
Get FastCGI values
Listening for FastCGI values

events.js:68
throw arguments[1]; // Unhandled 'error' event
^
Error: write EPIPE
at errnoException (net.js:769:11)
at Object.afterWrite (net.js:593:19)

root@ubuntu12:/tmp# node -v
v0.8.11

root@ubuntu12:/tmp# npm ls
/tmp
├─┬ [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └─┬ [email protected]
│ └── [email protected]
└─┬ [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ └─┬ [email protected]
│ └── [email protected]
└── [email protected]

crash if Status header not present

When I run the server with Example 1 (TinyFastCGI) from the FastCGI documentation (changing the incorrect "SERVER_HOSTNAME" to "SERVER_NAME" in the code), I get the following crash:

$ node node_modules/fastcgi/cli.js --port=8888 --socket=/tmp/tinyfcgi
Sending http requests to /tmp/tinyfcgi
Get FastCGI values
Listening for FastCGI values
FCGI values: {"FCGI_MAX_CONNS":1,"FCGI_MAX_REQS":1,"FCGI_MPXS_CONNS":0}
Listening on 0.0.0.0:8888
Ignoring management record: {"header":{"version":1,"type":10,"recordId":0,"contentLength":0,"paddingLength":0},"body":{},"bodies":[]}

http.js:1140
  var statusLine = 'HTTP/1.1 ' + statusCode.toString() + ' ' +
                                        ^
TypeError: Cannot call method 'toString' of undefined
    at ServerResponse.writeHead (http.js:1140:45)
    at send_stdout (/home/roy/Projects/node_modules/fastcgi/fastcgi.js:411:19)
at Parser.on_record [as onRecord] (/home/roy/Projects/node_modules/fastcgi/fastcgi.js:359:14)
at Parser._parser.execute (/home/roy/Projects/node_modules/fastcgi/node_modules/fastcgi-parser/lib/fastcgi.js:242:57)
at FastCGIStream.on_data (/home/roy/Projects/node_modules/fastcgi/fastcgi.js:320:12)
at FastCGIStream.EventEmitter.emit (events.js:95:17)
at FastCGIStream.emit_records (/home/roy/Projects/node_modules/fastcgi/stream.js:181:10)
at FastCGIStream.build_record (/home/roy/Projects/node_modules/fastcgi/stream.js:111:17)
at FastCGIStream.build_record (/home/roy/Projects/node_modules/fastcgi/stream.js:151:8)
at FastCGIStream.build_record (/home/roy/Projects/node_modules/fastcgi/stream.js:151:8)

This happens because the example does not include a Status: 200 header. According to the CGI specification, section 9.2 states:

If the script does not return a Status header, then "200 OK" should be assumed.

The easy workaround is to have the fcgi program return a Status header but it would be best if the fastcgi module (1) properly defaulted the status and (2) did not crash no matter what came over the socket.

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.