I’ve created a PHP Daemon script to continually monitor a particular directory on the server’s file system for new files, and then process and archive them.
Note: I’m using a php Daemon class provided at:
http://www.phpclasses.org/browse/file/8958.html
I’ve got the script running, but I need a way to interface with the daemon and issue commands. One really useful command, for instance, would be “STOP”! 🙂 I currently have to kill the process manually.
I’ve done this before using control files (i.e., check the file for a new command, execute it if one exists, then clear the file). I’ve also used sockets, but this problem doesn’t really call for any networking. Is there a better, more elegant or natural way to send command signals to the Daemon?
I did find this:
PHP Daemon/worker environment
But I’m afraid I don’t fully grasp how to use the provided code.
A possible solution would be to use signals — see
pcntl_signal, for instance : your PHP daemon would listen for signals, and you’d only have to send signals from “outside”.That’s a way that is quite often used on UNIX/Linux — but note that
pcntl_*functions will not be available on windows. (The class you posted is already usingpcntl*functions, so nothing new here)