note 97431 added to function.popen
| From: | hacklor | Date: | Mon, 19 Apr 2010 16:03:58 +0000 |
| Subject: | note 97431 added to function.popen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-168420@lists.php.net to get a copy of this message | ||
There is a simple way to start a process in the background but still find out what the process
result is. I combined the information from some users below with some of my own coming up with the
following:
<?php
$bat_filename = "C:\\my_bat_file.bat";
$bat_log_filename = "C:\\my_bat_file_bat.log";
$bat_file = fopen($bat_filename, "w");
if($bat_file) {
fwrite($bat_file, "@echo off"."\n");
fwrite($bat_file, "echo Starting proces >> ".$bat_log_filename."\n");
fwrite($bat_file, "php c:\\my_php_process.php >>
".$bat_log_filename."\n");
fwrite($bat_file, "echo End proces >> ".$bat_log_filename."\n");
fwrite($bat_file, "EXIT"."\n");
fclose($bat_file);
}
//
// Start the process in the background
//
$exe = "start /b ".$bat_filename;
if( pclose(popen($exe, 'r')) ) {
return true;
}
return false;
?>
In my case the file names of the .bat and .log files weren't always the same, so I needed a
dynamic way to create the .bat file. The output from the php command is saved to the log file with
the >> command. All prints and errors are stored there. At a later time you can open the log
file and see what happened.
----
Server IP: 69.147.83.197
Probable Submitter: 80.246.197.89
----
Manual Page -- http://www.php.net/manual/en/function.popen.php
Edit -- https://master.php.net/note/edit/97431
Del: integrated -- https://master.php.net/note/delete/97431/integrated
Del: useless -- https://master.php.net/note/delete/97431/useless
Del: bad code -- https://master.php.net/note/delete/97431/bad+code
Del: spam -- https://master.php.net/note/delete/97431/spam
Del: non-english -- https://master.php.net/note/delete/97431/non-english
Del: in docs -- https://master.php.net/note/delete/97431/in+docs
Del: other reasons-- https://master.php.net/note/delete/97431
Reject -- https://master.php.net/note/reject/97431
Search -- https://master.php.net/manage/user-notes.php