paragi / sphp

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

Error "PHP engine failed to start" #15

Closed thany closed 5 years ago

thany commented 6 years ago

I've copied your example script into a file test.js and adapted it slightly:

var express = require('express');
var sphp = require('sphp');
sphp.setOptions({ cgiEngine: "d:\\Projects\\php\\php-cgi.exe" });

var app = express();
var server = app.listen(8080);

app.use(sphp.express('/'));

That path is absolutely correct. I also tried with slashes instead of backslashes with no differece. Just to be sure.

This is the exact error I'm getting:

d:\Projects\Zenphoto\themes\thany>node test
d:\Projects\Zenphoto\themes\thany\node_modules\sphp\sphp.js:320
      throw new Error('PHP engine failed to start (' + sphp.cgiEngine +')');
      ^

Error: PHP engine failed to start (d:\Projects\php\php-cgi.exe)
    at ChildProcess.child.on (d:\Projects\Zenphoto\themes\thany\node_modules\sphp\sphp.js:320:13)
    at emitOne (events.js:116:13)
    at ChildProcess.emit (events.js:211:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:196:12)
    at onErrorNT (internal/child_process.js:372:16)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
    at Function.Module.runMain (module.js:695:11)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:612:3

I can copypaste that path, and sure enough, it's correct. PHP starts just fine. Well, it doesn't error immediately, and PHP directly from the CLI is rather useless, but still, it does actually work for what little it does. So why does it not work from sphp? What am I missing?

Software I'm using: Node 8.11.3 LTS PHP 7.2.11 x64 thread safe Windows 10

paragi commented 6 years ago

Apollon77 do you have any comments to that?

I lack the experience with windows to answer this. Except for the error in the error message, the issue seems to be that it can't find the executable file or don't have the permissions to run it.

Apollon77 commented 6 years ago

No idea beside enhancing L320 and also output the error variable ... maybe this helps seeing the real problem ?!

@thany: try adding " + error" to L320 output and say what it is

paragi commented 6 years ago

It seems that php-cgi doesn't return version.

what is the first line returned, with this in the command line interface?: D:\Projects\php\php-cgi.exe -v

What is the return code of the command? (I don't know how to test in windows)

paragi commented 6 years ago

It seem that a very common problem is that PHP is difficult to install as a stand alone CLI tool, on windows. If there is a problem with PHP, starting from the command line, it will show in a popup window. (For instance if the VC rumtime dll is not installed) The result will look excatly like the above issue.

PLEASE check that php-cgi is running correctly on your system: in CLI php-cgi -v

Apollon77 commented 6 years ago

@paragi But I still would prefer output of the real error in "catch" situations because normally this helps a lot to see the real reason. Also could be that the path is wrong and binary not found at all :-)

paragi commented 6 years ago

I agreed. Lets have a look at the error handling in general. How could we handle fatal errors in an event, if not with a throw?

The path is shown further down, The throw statement you see is just the stack trace. I was puzzled by that too :)