2010-01-24 26 views
1

基本上,我使用exec()来运行WinSCP,它导致脚本一直保留到文件上传。无论如何要让脚本继续,并且上传在后台运行?通过exec,挂起脚本上传文件

在Win7上运行PHP 5.3.1。

+1

换句话说:你想在PHP中使用多线程?现在你知道关键字:http://stackoverflow.com/search?q=php+multithreading – BalusC 2010-01-24 06:11:28

+0

这不是传统的方式多线程,即有多个程序执行线,通常互相发送消息。他只是想在后台产生另一个程序。如果你想以这种方式调用它,这是多线程更简单的方法。 – 2012-01-04 12:26:39

回答

0

请问这个function from the PHP Manual有帮助吗?

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"); 
} 

PHP on a windows machine; Start process in background then Kill process服用。

+0

这似乎没有工作。我跑了,我已经尝试了所有的例子以及http://www.somacon.com/p395.php – Tyler 2010-01-26 15:46:00

0

PHP不是作为一个单独的线程运行,所以apache必须等待它完成exec。在这种情况下,您的脚本可能会在执行调用期间遇到时间和内存限制,这对于用户exec来说不是最佳解决方案。一般不推荐。

为什么不使用ftp的PHP函数?双方在Linux和Windows http://www.php.net/manual/en/function.ftp-get.php

1
$pipe = popen("/bin/bash ./some_shell_script.sh argument_1","r"); 

作品。

(不要关闭管,也不要试图从中读取)

你的PHP脚本将继续运行,而过程中,通过在后台运行POPEN催生。当脚本到达文件结尾或调用die()时,它将等待另一个进程完成,并在完全退出之前关闭管道。