Skip to content

Instantly share code, notes, and snippets.

@mtrudel
Created November 26, 2010 15:59
Show Gist options
  • Select an option

  • Save mtrudel/716883 to your computer and use it in GitHub Desktop.

Select an option

Save mtrudel/716883 to your computer and use it in GitHub Desktop.
function run_function($name, $params) {
// Actually run the function in question
}
while(true) {
// Wait for a connection and extract the function to start
if (function_exists('pcntl_fork')) {
$pid = pcntl_fork();
if ($pid == -1) {
die('could not fork a child -- something is wrong');
} else if ($pid) {
// we are the parent. Nothing to do here, so just wrap back around the loop
} else {
// we are the child. Run the function
run_function($name, $params);
}
} else {
// We don't have pcntl, so just run in process
run_function($name, $params);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment