简体   繁体   English

如何在带有Node.js / Socket.IO的PHP中使用popen?

[英]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 . 通过这个Stack Overflow问题 ,我意识到您可以使用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. 它将中断,并给我带来许多与Node.js相关的错误。

Why is this? 为什么是这样? When I try node nodeServer.js in command prompt, it works fine. 当我在命令提示符下尝试node nodeServer.js时,它工作正常。

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. 如果您只是想使节点服务器保持活动状态,则可以使节点服务器进程与GNU Screen一起运行。 ( http://www.gnu.org/software/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; 您将能够关闭SSH终端并从其他计算机/位置打开它,并能够重新连接到会话。 all without having your server stop. 所有这些都无需停止服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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