note 32291 deleted from ref.exec by tomsommer

From: Date: Sat, 03 Jul 2004 14:58:03 +0000
Subject: note 32291 deleted from ref.exec by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-72470@lists.php.net to get a copy of this message
Note Submitter: josep ---- I have tried almost every possible combination of commands for system() and exec(). My goal was to launch a process in the OS and go back to my stuff without waiting for it to finish. For some reason I have been unable to succeed. Im using WindowsXP Pro(SP1) + Apache 2.0.45 + PHP 4.3.1 (as a module). Finally, Ive managed to do it with a workaround. Instead of launching the command directly, I create a BAT file that does it. Then, I issue the command "at" with the BAT file as a parameter. This command returns immediately. The following code illustrates this: ----------------------------------------------------- $idimport = getIdImport(); // Flush session info session_write_close(); // Create the BAT file $fp = @fopen( "./createreports.cgi.bat", "wb" ); @fwrite( $fp, "cd ".realpath('.')."\r\n" ); @fwrite( $fp, "c:\\php\\cli\\php.exe createreports.cgi.php ".$idimport."\r\n" ); @fclose( $fp ); // Launch the AT command // Time is set to the next minute $result = system( 'at '.date("H:i",time()+60).' '.realpath('.').'\createreports.cgi.bat', $retVar ); ----------------------------------------------------- Before struggling with PHP, create a BAT file by hand and double-check that it works. Then add it manually to AT. Check it again. If everything is fine, you can automate it. Ive had issues with directories. Note that the AT command knows nothing about your "current" directory: you must use full paths. I have wasted a whole day looking for information and solutions to use exec() and system() and it is sad that they are so poorly implemented on Win32 platforms.

« previous php.notes (#72470) next »