php脚本一直运行
一个简单的解决方案
nohup php script.php &
因此,您在后台运行脚本并断开进程与终端的连接。 如果它没有帮助,请尝试后面的disown命令。 这些命令之间的差异的详细解释有一个很好的答案 。
要完全控制您的脚本,一个很好的选择是System V init脚本。 您可以使用https://github.com/fhd/init-script-template上的模板。
将模板复制到/etc/init.d目录并重命名。 在模板中,您需要更改变量:
dir="/your/working/directory"
cmd="nohup php script.php"
user="your user"
这样做,您将能够控制您的脚本
/etc/init.d/your_script start
/etc/init.d/your_script stop
确保您有权写入/var/log/和/var/run/ ,或以sudo身份运行脚本(leave user="" empty)
A simple solution is
nohup php script.php &
So you run script in background and disconnect the process from the terminal. If it doesn't help, try disown command after it. There is a good answer with detailed explanation of differences between these commands.
To get full control of your script, a good choice would be a System V init script. There is a template at https://github.com/fhd/init-script-template, which you can use.
Copy template to /etc/init.d directory and rename it. In template you need to change variables:
dir="/your/working/directory"
cmd="nohup php script.php"
user="your user"
Doing that you will be able to control your script by
/etc/init.d/your_script start
/etc/init.d/your_script stop
Make sure you have permissions to write in /var/log/ and /var/run/, or run script as sudo(leave user="" empty)
https://www.656463.com/wenda/zhtyxphpjbyybhslinux_553

浙公网安备 33010602011771号