Run php script as daemon process

原创
2017/03/04 14:00
阅读数 53

 

  1. Supervisor 推荐!活跃度比较高。但是目前依赖Python
  2. upstart 类似init的替换品
  3. daemon tools
  4. php simple daemon
  5. linux tool: start-stop-daemon 比较简单的一种
  6. nohup php script.php & 不可靠的一种
  7. pear package System_Daemon 最后更新日期2012-03-13,估计没人维护了,可以了解一下,其使用介绍的文章

 

upstart example

How to set it up:

Create a new script file at /etc/init/myphpworker.conf. Here is an example:

# Info
description "My PHP Worker"
author      "Jonathan"

# Events
start on startup
stop on shutdown

# Automatically respawn
respawn
respawn limit 20 5

# Run the script!
# Note, in this example, if your PHP script returns
# the string "ERROR", the daemon will stop itself.
script
    [ $(exec /usr/bin/php -f /path/to/your/script.php) = 'ERROR' ] && ( stop; exit 1; )
end script
Starting & stopping your daemon:

sudo service myphpworker start
sudo service myphpworker stop
Check if your daemon is running:

sudo service myphpworker status

 

展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部