Windows / php pclose和popen问题

问题描述 投票:1回答:1

这是我的代码:

<?php
    require_once 'dbconnect.php';
    function execInBackground($cmd) { 
        if (substr(php_uname(), 0, 7) == "Windows"){ 
            pclose(popen("start /B ". $cmd, "r"));  
        } 
        else { 
            exec($cmd . " > /dev/null &");   
        } 
    } 

    if(isset($_GET['date'])){
        //CHECK LOCK
        $checkLock = "Select IS_FREE_LOCK('overnight') as `lock`;";
        $result = mysql_query($checkLock) or die(mysql_error());
        while($information = mysql_fetch_array($result)){
            if($information['lock'] == 0){
                die('Overnight is already running, please try again later.');
            }
        }
        execInBackground("php overnightQueries.php {$_GET['date']}");
        //echo "<pre>".print_r($output2, true)."</pre>";
        header('Refresh: 3; url=index.php');
        die('running queries...');
    }
    else {

        die('PLEASE SET DATE');

    }
?>

我正在使用Windows机器。

我收到以下警告:

警告:popen(start / B php overnightQueries.php 2011_08_12,r):第5行的C:\ inetpub \ GTSA \ runOvernight.php没有错误

和:

警告:pclose()期望参数1是资源,布局在第5行的C:\ inetpub \ GTSA \ runOvernight.php中给出

php windows iis popen pclose
1个回答
0
投票
$handle = popen("start /B ". $cmd, "r");  
if ($handle === FALSE) {
   die("Unable to execute $cmd");
}
pclose($handle);

如果出现问题,popen会返回false,你会盲目地传递给pclose,因此第二个错误。

至于第一个错误,请检查PHP是否在您的环境路径中 - 您可能需要指定php.exe的绝对路径。

© www.soinside.com 2019 - 2024. All rights reserved.