Search code examples
phpapachepcntl

how to use pcntl_fork() with Apache?


This is my code, inside index.php (just an example):

$pid = pcntl_fork();
if ($pid == -1) {
  die("failed to fork");
} else if ($pid) {
  // nothing to do
} else {
  putDataIntoWebService();
  exit();
}
echo "normal page content";

This snippet works fine in command line. In Apache exit() kills them both, the parent and the kid process. What is a workaround?


Solution

  • This is the solution:

    posix_kill(getmypid(), SIGKILL);
    

    instead of exit().