views:

140

answers:

2

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:
http://stackoverflow.com/questions/752214/php-daemon-worker-environment
But I'm afraid I don't fully grasp how to use the provided code.

+1  A: 

On *nix you can use signals to control your daemon; seepcntl_signal() and the signal(7) man page.

Ignacio Vazquez-Abrams
+2  A: 

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 using pcntl* functions, so nothing new here)

Pascal MARTIN