Skip to content

Instantly share code, notes, and snippets.

@giansalex
Created January 21, 2018 23:09
Show Gist options
  • Save giansalex/26f461473c962b7050466604ba077516 to your computer and use it in GitHub Desktop.
Save giansalex/26f461473c962b7050466604ba077516 to your computer and use it in GitHub Desktop.
Execute $cmd in the background (no cmd window) without PHP waiting for it to finish, on both Windows and Unix.
<?php
function execInBackground($cmd) {
if (substr(php_uname(), 0, 7) == "Windows"){
pclose(popen("start /B ". $cmd, "r"));
}
else {
exec($cmd . " > /dev/null &");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment