So to start I was building a NodeJS application that works alongside a front-end of a website. This is built and what I want is to launch it via PHP. So you can click save, which then starts it, if it is needed.
The application is a websocket server, and will listen on a websocket and process data/commands from a client (the front-end of my website).
Now the code I am using to launch it is as follows:
$command = '/usr/local/bin/node main.js & echo $!';
$processid = shell_exec($command);
But for some reason when I click save on the front-end it just hangs and keeps loading... but showing nothing on the page? It creates the process as I can see it doing:
lsof -i tcp:8000
and the page only stops loading when I kill the process that node is running...
I am using:
kill -9 <pid>
to kill it. So I am a little lost on why it's not running it in the background and then finishing the PHP scripts... it just hangs on it?
Any help would be appreciated.
Once note, is that it all runs from the command line fine, so the file is a separate launcher class, and if I run it via php and add some code to do tasks it works, it's only when I call it from something else I have the issue?
If it helps; the framework that the website uses is Joomla 3.x, thanks in advance.
I am on a MacBook Air El Capitan, Will also need to work on Linux CentOS
Use this. It will suppress both STDOUT and STDERR and return immediately without waiting for command to finish.
$command = '/usr/local/bin/node main.js > /dev/null 2>&1';