paragi / sphp

A snappy PHP execution module / middleware
46 stars 14 forks source link

events.js:141 throw er; // Unhandled 'error' event ^ Error: spawn php-cgi ENOENT #3

Closed gavinengel closed 8 years ago

gavinengel commented 8 years ago

Hi there! Any advice for me on this error, please?

gavin:~/workspace/misc/sphp$ node example.js 
Unable to start worker:php-cgi
Unable to start worker:php-cgi
==========================================================================
PHP Workers spares: 2  min: 2  Max: 10
==========================================================================
events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: spawn php-cgi ENOENT
    at exports._errnoException (util.js:874:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32)
    at onErrorNT (internal/child_process.js:344:16)
    at doNTCallback2 (node.js:441:9)
    at process._tickCallback (node.js:355:17)
    at Function.Module.runMain (module.js:469:11)
    at startup (node.js:136:18)
    at node.js:963:3
gavin:~/workspace/misc/sphp$ npm -v
3.5.1
gavin:~/workspace/misc/sphp$ node -v
v4.2.3
gavin:~/workspace/misc/sphp$ cat /etc/issue
Ubuntu 14.04.3 LTS \n \l

gavin@:~/workspace/misc/sphp$ php -v
PHP 5.6.16-2+deb.sury.org~trusty+1 (cli) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
    with Xdebug v2.3.2, Copyright (c) 2002-2015, by Derick Rethans
paragi commented 8 years ago

||

Hi Gavin

Are you setting the cgiEngine to point to your installation of PHP?

Defaults is 'php-cgi' that must be in the path. use: sphp.cgiEngine='php'; or full path i necessary

It seem that you are not using php-cgi, but rather php as cli. I have not tested that configuration. There might be side effects (but not this one)

Please tell me if that solves you issue

Best regards Simon

paragi commented 8 years ago

Hi Gavin

You must install php-cgi for this example to work.

php (cli) has no HTTP header support and other features, that makes it unsuitable for a server.

Is there any good reason why it should be made compatible with the php (cli) version?

Please let me know if this helps.

Best regards Simon

gavinengel commented 8 years ago

Would fastcgi work?

paragi commented 8 years ago

As I understand it, fastcgi is a deamon? If such you would need a stream to communicate with it. If that is what you need, you should have a look at one of the node fastcgi projects.

sphp works with the php-cgi version. I bet that it could be made to work with both other version, but I haven't done it.

gavinengel commented 8 years ago

Why would I use CGI instead of FastCGI? Isn't FastCGI, ummm, faster?

paragi commented 8 years ago

FastCGI is a method of invoking a CGI; A process manager that clones the php process when needed. sphp is a process manager too, but loads the process preemptively, and hold it until needed. While FastCGI are more "resource friendly" I expect that sphp has a faster responsetime on low to moderate load. (A benchmark test would be nice :c)

Speed is one reason for using sphp, Another is the way a request is transferred to php, enabling node session and websocket support. That is not possible with the FastCGI projects. (takes a "preburner" script to initialize php globals)

To merge those to approaches would be a natural evolution of this project. But I don't have the time right now. Should anyone wish to implement it, I would be happy to assist.

Please let me know if you solved the problem by installing php-cgi

On derbian: sudo apt-get install php5-cgi

david-j-davis commented 7 years ago

Im having this same error. I guess I don't understand why I need php-cgi. Before I ran into this npm module I was running a php server like php -S localhost:3000, and that works like a charm. So I'm pretty sure I have Apache processing my php. Think Im at a dead end here.

paragi commented 7 years ago

You need the php-cgi version installed to use this module. The reason is that it is necessary to use this handler to achieve the specified functionality.

You can change the engine specifically:

sphp.cgiEngine='php';

Was that your question?

steffanhalv commented 7 years ago

@paragi Hi, I get this same issue running on mac.

php-cgi is in the path and executes fine from the terminal:

php-cgi -v
PHP 7.1.3 (cgi-fcgi) (built: Mar 28 2017 21:57:37)
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies

But when accessing my index.php file from express server it executes this exception:

Steffans-Mac-mini:cloud-npm-php steffanhalvorsen$ npm run start

> cloud-npm-php@1.0.0 start /Users/steffanhalvorsen/Documents/npm/cloud-npm-php
> node ./bin/www

Unable to start worker:php-cgi
events.js:163
      throw er; // Unhandled 'error' event
      ^

Error: spawn php-cgi ENOENT
    at exports._errnoException (util.js:1034:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
    at onErrorNT (internal/child_process.js:367:16)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)

If I switch from sphp.cgiEngine='php-cgi'; to sphp.cgiEngine='php';

I can access my index.php file without error, but it doesnt return anything, just an empty page, and my 'Hello world!' doesnt show up:

index.php:

<?php

echo "Hello World!";