note 116948 added to function.popen
| From: | anonymous at anon dot com | Date: | Wed, 25 Mar 2015 22:28:26 +0000 |
| Subject: | note 116948 added to function.popen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-202035@lists.php.net to get a copy of this message | ||
As a side note to the code provided by anonymous at anon dot com:
$cmd = "php longscript.php";
function execInBackground($cmd) {
if (substr(php_uname(), 0, 7) == "Windows"){
pclose(popen("start /B ". $cmd, "r"));
} else {
exec($cmd . " > /dev/null &");
}
}
I had a problem where Windows would close the call too fast before the entire script was
interpreted, but I didn't want my main script to hang until it would be fully loaded.
As a workaround, I called a tiny .php script which would then call the larger script.
myfile.php:
<?php
$cmd = "php timewrapper.php";
function execInBackground($cmd) {
if (substr(php_uname(), 0, 7) == "Windows"){
pclose(popen("start /B ". $cmd, "r"));
} else {
exec($cmd . " > /dev/null &");
}
}
?>
timewrapper.php:
<?php
$cmd = "php longscript.php";
$timer = popen("start /B ". $cmd, "r");
sleep(30);
pclose($timer);
?>
This way my main script would continue to run without having to pause, while the tiny script pauses
while it loads the larger file.
----
Server IP: 72.52.91.14
Probable Submitter: 77.161.170.176
----
Manual Page -- http://php.net/manual/en/function.popen.php
Edit -- https://master.php.net/note/edit/116948
Del: integrated -- https://master.php.net/note/delete/116948/integrated
Del: useless -- https://master.php.net/note/delete/116948/useless
Del: bad code -- https://master.php.net/note/delete/116948/bad+code
Del: spam -- https://master.php.net/note/delete/116948/spam
Del: non-english -- https://master.php.net/note/delete/116948/non-english
Del: in docs -- https://master.php.net/note/delete/116948/in+docs
Del: other reasons-- https://master.php.net/note/delete/116948
Reject -- https://master.php.net/note/reject/116948
Search -- https://master.php.net/manage/user-notes.php