Windows/php pclose和popen问题

时间:2022-11-25 05:55:15

Here is my code:

这是我的代码:

<?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');

    }
?>

I am using a windows machine.

我正在使用一台windows机器。

I get the following warnings:

我得到以下警告:

Warning: popen(start /B php overnightQueries.php 2011_08_12,r): No error in C:\inetpub\GTSA\runOvernight.php on line 5

警告:popen(启动/B php通宵查询)。php 2011_08_12,r): C:\inetpub\GTSA\ runnight没有错误。php在第5行

AND:

和:

Warning: pclose() expects parameter 1 to be resource, boolean given in C:\inetpub\GTSA\runOvernight.php on line 5

警告:pclose()期望参数1是resource, boolean (C:\inetpub\GTSA\ runnight)。php在第5行

1 个解决方案

#1


0  

$handle = popen("start /B ". $cmd, "r");  
if ($handle === FALSE) {
   die("Unable to execute $cmd");
}
pclose($handle);

popen returns false if there was a problem, which you blindly pass to pclose, hence the second error.

如果出现问题,popen返回false,您盲目地将其传递给pclose,从而导致第二个错误。

As for the first error, check that PHP is in your environment's path - you may need to specify an absolute path to php.exe.

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

#1


0  

$handle = popen("start /B ". $cmd, "r");  
if ($handle === FALSE) {
   die("Unable to execute $cmd");
}
pclose($handle);

popen returns false if there was a problem, which you blindly pass to pclose, hence the second error.

如果出现问题,popen返回false,您盲目地将其传递给pclose,从而导致第二个错误。

As for the first error, check that PHP is in your environment's path - you may need to specify an absolute path to php.exe.

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