Basically in a nu开发者_开发知识库tshell is I am using exec() to run WinSCP, which is causing the script to hold until the file is uploaded. Is there anyway to make it so that the script continues, and the upload runs in the background?
Running PHP 5.3.1 on Win7.
$pipe = popen("/bin/bash ./some_shell_script.sh argument_1","r");
Works both under Linux and Windows.
(just don't close the pipe and don't try to read from it)
Your PHP script will continue to run while the process spawned through popen runs in the background. When your script reaches the end of file or a call to die(), it will wait for the other process to finish and the pipe to close before quitting completely.
Will this function from the PHP Manual help?
function runAsynchronously($path,$arguments) {
$WshShell = new COM("WScript.Shell");
$oShellLink = $WshShell->CreateShortcut("temp.lnk");
$oShellLink->TargetPath = $path;
$oShellLink->Arguments = $arguments;
$oShellLink->WorkingDirectory = dirname($path);
$oShellLink->WindowStyle = 1;
$oShellLink->Save();
$oExec = $WshShell->Run("temp.lnk", 7, false);
unset($WshShell,$oShellLink,$oExec);
unlink("temp.lnk");
}
Taken from PHP on a windows machine; Start process in background then Kill process.
PHP isn't designed to run as a separate thread so apache has to wait for it to complete the exec. This being the case, your script could run into time and memory constraints during an exec call which would make it a less than optimal solution to user exec. Generally not recommended.
Why not use the PHP functions for ftp? http://www.php.net/manual/en/function.ftp-get.php
精彩评论