You should use php's pcntl_fork() (as recommended by @bmdhacks).
The basics process is, fork, setsid, fork again, chdir to /, and close all your open file descriptors. Standard practice also dictates that you create a file called /var/run/$NAME
, (where $NAME is your daemon's name), and write the PID to that file, so that you can control the process execution later on.
I'm not a php programmer, but this is standard *nix stuff.
The best php example I can google looks like this hello-world-daemon-with-fork
But, he doesn't change his working directory to '/', nor does it look like he closed open file descriptors (I'm not sure how this would work in php), so that he's not connected to the stdin, stdout, and stderr of the original process.
I dug a little more, and found another article which may help with php's pcntl_fork()
And, it looks like there's a pear module called System_Daemon, which handles this for you (I found it through here).