Long living PHP scripts ● Never run them from the browser or from the web server. ● Browser can time out. ● Web server times out. ● Solution: Run from the command line on the server.
The Proper Way ● Use PHP Process Control extension. ● “... implements the Unix style of process creation, program execution, signal handling and process termination.” ● http://sg2.php.net/pcntl ● Example: http://sg2.php.net/manual/en/pcntl. example.php
An Easier Way ● Use Clio - Lightweight utility and helper classes for PHP CLI applications ● https://github.com/nramenta/clio ● Example: ○ https://github.com/CoderKungfu/php- queue/tree/master/demo/runners
Making the Daemon Service (CentOS/Redhat) Add this to the top: And run this command: #!/usr/bin/php # # MyAwesomeDaemon Starts the PHP-Queue runner for BlahDaemon # # chkconfig: - 91 91 # description: Runner for blah daemon. $ chkconfig --levels 235 BeanstalkSampleDaemon on