开发者

Windows/php pclose and popen issue

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.');
            }
开发者_C百科        }
        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.

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

AND:

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


$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.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜