daemon without pcntl_fork
| From: | Jim Lucas | Date: | Tue, 18 Aug 2009 00:14:26 +0000 |
| Subject: | daemon without pcntl_fork | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-296905@lists.php.net to get a copy of this message | ||
Does anybody know how to use PHP as a daemon without the use of pcntl_fork.
http://php.net/pcntl_fork
I don't want to have to have a person have a special/custom compilation
of PHP just to run a simple daemon.
My system: OpenBSD 4.5 w/PHP v5.2.8
I want to launch a daemon out of the /etc/rc.local when the system starts.
My goal is to write a script that will be launched from /etc/rc.local
when a system boots. I want it to be detached from any shell or ssh
login that I launch it from also.
Anybody have any idea on how to do this?
I have played with system() and it does work.
test.php:
<?php
echo 'Starting';
system('/usr/local/bin/php test_cli.php >/dev/null &');
echo 'Done';
?>
test_cli.php
<?php
for( $i=1; $i<=10; $i++ ) {
echo "Echo {$i}\n";
sleep(1);
}
echo 'Done';
?>
The above, when called, launches test_cli.php and detaches it from the
cli and returns to the system prompt
Well, after writing all this out, I think I have answered by own question.
If anybody else has a better suggestion, I am all ears.
If you have a better way of doing it, please share.
Also, a second piece to this would be a script to manage
(start/stop/restart/etc...) the parent daemon.
Something along the line of apachectl or similar.
TIA!
Update to the last email also.
I found another device that does RS232 to ethernet:
http://www.hw-group.com/products/portstore2/index_en.html
Anybody work with one of these?
Again, thanks!
Jim Lucas