Skip to content

Instantly share code, notes, and snippets.

@cbednarski
Created June 21, 2011 21:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cbednarski/1038947 to your computer and use it in GitHub Desktop.
Save cbednarski/1038947 to your computer and use it in GitHub Desktop.
Detach a process from an apache web request
<?php
/**
* Detaches a process from apache so it can be invoked by a webpage but run
* under CLI context. Prevents apache from waiting for the process to
* finish before displaying output. All output is piped to null.
*
* @param string $process full path to executable / binary
* @param string $arguments arguments passed to the script
*/
function detachProcess($process)
{
if(stripos(php_uname(), 'Windows') !== false) {
// Windows - from http://stackoverflow.com/questions/2067900
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run(addslashes($process), 7, false);
unset($WshShell, $oExec);
}
else {
// Linux
$command = "$process > /dev/null &";
exec($command);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment