Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在编写一个我想在后台运行的 PHP 脚本(好的,它是一个守护进程),它遵循以下伪代码:
do { // stuff sleep(60*30); // 30 minutes } while(1);
现在,我如何设置这个婴儿在服务器重新启动时自动运行。我不需要担心状态,因为所有内容都存储在 MySQL 数据库中——它应该能够从它停止的地方继续。
我Ubuntu 12.04 x64在 AWS 上使用服务器(如果重要的话)。
Ubuntu 12.04 x64
谢谢!
作为您特定问题的解决方案,使用 bash 脚本执行 PHP cli Pusedo 代码将是
\usr\sbin\php -q \home\user\myphpscript.php
这将在没有任何时间限制的情况下执行 PHP 脚本,但是由于您使用 PHP CLI,您可能无法获得一些特定于 Web 的环境变量,但对于这样的后台进程,您几乎不需要它们。