Created
June 21, 2011 21:27
-
-
Save cbednarski/1038947 to your computer and use it in GitHub Desktop.
Detach a process from an apache web request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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