Workaround to pcntl_fork() not being usable when PHP is run as an Apache module
function background_job($program, $args)
{
# The following doesn't work when running PHP as an apache module
/*
$pid = pcntl_fork();
pcntl_signal(SIGCHLD, SIG_IGN);
if ($pid == 0)
{
posix_setsid();
pcntl_exec($program, $args, $_ENV);
exit(0);
}
*/
# Workaround
$args = join(' ', array_map('escapeshellarg', $args));
exec("$program $args 2>/dev/null >&- /dev/null &");
}