Run php script as daemon process

后端 未结 14 1458
-上瘾入骨i
-上瘾入骨i 2020-11-22 11:36

I need to run a php script as daemon process (wait for instructions and do stuff). cron job will not do it for me because actions need to be taken as soon as instruction arr

相关标签:
14条回答
  • 2020-11-22 12:32

    I wrote and deployed a simple php-daemon, code is online here

    https://github.com/jmullee/PhpUnixDaemon

    Features: privilege dropping, signal handling, logging

    I used it in a queue-handler (use case: trigger a lengthy operation from a web page, without making the page-generating php wait, i.e. launch an asynchronous operation) https://github.com/jmullee/PhpIPCMessageQueue

    0 讨论(0)
  • 2020-11-22 12:34

    I run a large number of PHP daemons.

    I agree with you that PHP is not the best (or even a good) language for doing this, but the daemons share code with the web-facing components so overall it is a good solution for us.

    We use daemontools for this. It is smart, clean and reliable. In fact we use it for running all of our daemons.

    You can check this out at http://cr.yp.to/daemontools.html.

    EDIT: A quick list of features.

    • Automatically starts the daemon on reboot
    • Automatically restart dameon on failure
    • Logging is handled for you, including rollover and pruning
    • Management interface: 'svc' and 'svstat'
    • UNIX friendly (not a plus for everyone perhaps)
    0 讨论(0)
提交回复
热议问题