«

»

Mar 28

Run PHP scripts as daemons

I have been messing around with Tiny Tiny RSS ever since Google announced that they are ending Google Reader. I want Tiny Tiny RSS to automatically update the feeds for me, without the need for me to update them manually. That way when I login I always have the most current feeds.

While reading the wiki on how to set this update. I saw they had to main ways one with a PHP script and the other is a cron job. I liked the idea of a PHP script that pretty much be run in the background. They listed a program called start-stop-daemon tools for Debian based systems. I tried to set that up but it turned out to be way harder then they originally stated. After I couldn’t get that to work I tried to search Google for another solution. I tried a few different options, thats when I found php-daemon.

PHP-Daemon allows you to create a daemon from a php script by adding two lines of code at the top of your .PHP file. It basically just includes a file called daemon.php. After your done it adds a few commands to the php file that you can use. “php yourscript.php {status|start|stop|restart|reload|kill}”

Once I added the two lines of code at the top of my PHP file I ran "PHP update_daemon2.php start"
php_daemon_start




I can even check the status to see if it is running or not
php_daemon_status




This is the easiest way to daemonize a PHP script.