0

From this Stack Overflow question, I realised you could keep a process running as a daemon in the background with popen.

But when I tried this:

$daemon = popen('node nodeServer.js', 'r');
echo "Server started.\n";

It would break, and give me lots of Node.js-related errors.

Why is this? When I try node nodeServer.js in command prompt, it works fine.

Here's the errors I got:

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: write EPIPE
    at errnoException (net.js:901:11)
    at Object.afterWrite (net.js:718:19)

Thanks.

Community
  • 1
  • 1
Lucas
  • 16,930
  • 31
  • 110
  • 182
  • It'd be helpful if you told us what those errors were. Is node in the path of whatever shell PHP is opening? Does PHP have permission to run that executable? Does it have permission to read that .js file? You've provided basically no useful details, and until you do, we can't help you with anything but vague guesses. – Marc B Feb 15 '14 at 00:38
  • @MarcB I updated my question, please take a look. – Lucas Feb 15 '14 at 00:41

1 Answers1

0

If you're just trying to keep your Node server alive, you can keep the node server process running with GNU Screen. (http://www.gnu.org/software/screen/)

You'll be able to close the SSH terminal and open it from a different computer/location and have the ability to re-attach to a session; all without having your server stop.

Justin
  • 400
  • 1
  • 5
  • 16