?php function daemon(){ $pid = pcntl_fork(); if ($pid == -1) { exit(1); } elseif ($pid 0) { exit(0); } else { posix_setsid(); umask(0); chdir('/'); fclose(STDOUT); fclose(STDERR); $pid = pcntl_fork(); if ($pid == -1) { exit(1); } elseif ($p
<?php
function daemon()
{
$pid = pcntl_fork();
if ($pid == -1)
{
exit(1);
}
elseif ($pid > 0)
{
exit(0);
}
else
{
posix_setsid();
umask(0);
chdir('/');
fclose(STDOUT);
fclose(STDERR);
$pid = pcntl_fork();
if ($pid == -1)
{
exit(1);
}
elseif ($pid > 0)
{
exit(0);
}
else
{
unset($pid);
}
}
}
function job()
{
// your job here
}
daemon();
while (true)
{
job();
sleep(1);
}
