Voting

: min(six, nine)?
(Example: nine)

The Note You're Voting On

atampone at NOSPAMFORME dot trdsupra dot com
19 years ago
If you want to fork a process under windows, this is the function to use. I created a batch file called runcmd.bat with the following line

start %1 %2 %3 %4

then I have the folowing function

<?php
define
('RUNCMDPATH', 'c:\\htdocs\\nonwebspace\\runcmd.bat');

function
runCmd($cmd) {
$externalProcess=popen(RUNCMDPATH.' '.$cmd, 'r');
pclose($externalProcess);
}
?>

with this, doing something like

<?php runCmd('php.exe printWorkOrder.php 3498'); ?>
will launch php.exe outside of apache and allow the script calling the runCmd() function to continue without waiting for the command line process to return. The process will run under the same user account that Apache (or whatever webserver you're running) is running under, so make sure it has permissions to do whatever you need to do. Also, make sure that the batch file has enough %n s in order to pass all the command line variables that you might need to pass.

Special thanks to kicken from the devshed forums for coming up with the idea.

<< Back to user notes page

To Top