daemonizing a command line script
This commit is contained in:
parent
b7d382d470
commit
00969ebd03
24
cli/daemonized
Executable file
24
cli/daemonized
Executable file
@ -0,0 +1,24 @@
|
|||||||
|
#!/usr/bin/php -q
|
||||||
|
<?php
|
||||||
|
|
||||||
|
set_time_limit(0); // Remove time limit
|
||||||
|
|
||||||
|
if (pcntl_fork()) { // Fork process
|
||||||
|
printf("Daemon running.\n");
|
||||||
|
} else {
|
||||||
|
$sid = posix_setsid(); // Make child process session leader
|
||||||
|
|
||||||
|
if ($sid < 0) {
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
$outfile = fopen('daemon.log', 'a+');
|
||||||
|
fwrite($outfile, time() . " Hello World via command line daemon!\n");
|
||||||
|
fclose($outfile);
|
||||||
|
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
Loading…
Reference in New Issue
Block a user