简体   繁体   中英

How can I use popen in PHP with Node.js/Socket.IO?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM