在raspban上运行一个php脚本作为守护进程


Run a php script as daemon on raspban

我写了一个工作PHP脚本,作为一个Websocket服务器,有一个无休止的while(true)循环。

你能帮我吗:

  1. 启动时启动PHP脚本
  2. 通过ssh启动-停止PHP脚本
  3. 我读到关于PHP无休止循环内存不足(ref)的文章,那么有更好的方法来维护websocket服务器吗

仅供参考:我有Apache;PHP;MySQL;systemd已安装,并希望避免安装其他任何东西!

我尝试过的

  • 编写init.d/service(如Bram.us所述)并启动它,但是:

    sudo /etc/init.d/myservice start

    sudo: unable to execute /etc/init.d/myservice: No such file or directory

  • 安装暴发户sudo apt-get install upstart并在/etc/init/with:下写入配置文件

    start on filesystem and net-device-up IFACE=eth0 respawn exec /usr/bin/php -f /path/to/your/script.php

但在那之后我再也不能完全启动了。。。所以我回到了系统

谢谢!

使用Upstart可以执行以下操作:

配置文件(在/etc/init/中)-

start on filesystem and net-device-up IFACE=eth0
respawn
exec /usr/bin/php -f /path/to/your/script.php

这将在启动时执行脚本,并在需要时重新生成。我们以完全相同的方式运行websocket服务,并且没有内存泄漏的问题。