note 88543 modified in function.system by danbrown

From: Date: Wed, 28 Jan 2009 17:35:43 +0000
Subject: note 88543 modified in function.system by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-149898@lists.php.net to get a copy of this message
I found a lot of solutions how to run app asynchronously in background, but nothig works. :( But now I have a solution. <?php function runAsynchronously($path) { $WshShell = new COM("WScript.Shell"); $spustec = getcwd()."\\_".uniqid().".php"; #Generate PHP code to run app and save it into file $spoustec fwrite(($fp = fopen($spustec,"w+")),"<?php chdir(dirname(__FILE__));\$command = \"".addslashes($path)."\";echo \"Now running external program...\n\n\";system(\$command);echo \"Now deleting...\";unlink(__FILE__); ?>"); fclose($fp); # Now run $spoustec -> it will start $path $oExec = $WshShell->Run($spustec, 7, false); unset($WshShell,$oExec); } runAsynchronously("notepad"); // Will open notepad, but it will continue excuting the PHP code echo "Running :)\n\n"; sleep(1); ?> (Tested on Win7) I spend a lot of time on it. So I hope that this will help you. P.S.: Sorry for my English. ;) --was-- I found a lot of solutions how to run app asynchronously in background, but nothig works. :( But now I have a solution. <? function runAsynchronously($path) { $WshShell = new COM("WScript.Shell"); $spustec = getcwd()."\\_".uniqid().".php"; #Generate PHP code to run app and save it into file $spoustec fwrite(($fp = fopen($spustec,"w+")),"<?php chdir(dirname(__FILE__));\$command = \"".addslashes($path)."\";echo \"Now running external program...\n\n\";system(\$command);echo \"Now deleting...\";unlink(__FILE__); ?>"); fclose($fp); # Now run $spoustec -> it will start $path $oExec = $WshShell->Run($spustec, 7, false); unset($WshShell,$oExec); } runAsynchronously("notepad"); // Will open notepad, but it will continue excuting the PHP code echo "Running :)\n\n"; sleep(1); ?> (Tested on Win7) I spend a lot of time on it. So I hope that this will help you. P.S.: Sorry for my English. ;) http://php.net/manual/en/function.system.php

« previous php.notes (#149898) next »