note 32291 added to ref.exec
| From: | josep at rack1 dot php dot net | Date: | Thu, 22 May 2003 17:01:08 +0000 |
| Subject: | note 32291 added to ref.exec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-48838@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/ref.exec.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32291
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32291&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32291&report=yes