Windows/php pclose和popen问题 [英] Windows/php pclose and popen issue
问题描述
这是我的代码:
<?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计算机.
I am using a windows machine.
我收到以下警告:
警告:popen(夜间启动/B phpQueries.php 2011_08_12,r):在第5行的C:\ inetpub \ GTSA \ runOvernight.php中没有错误
Warning: popen(start /B php overnightQueries.php 2011_08_12,r): No error in C:\inetpub\GTSA\runOvernight.php on line 5
AND:
警告:pclose()期望参数1为资源,在第5行的C:\ inetpub \ GTSA \ runOvernight.php中给出布尔值
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返回false,您将其盲目传递给pclose,因此是第二个错误.
popen returns false if there was a problem, which you blindly pass to pclose, hence the second error.
对于第一个错误,请检查PHP是否在您环境的路径中-您可能需要指定php.exe的绝对路径.
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.
这篇关于Windows/php pclose和popen问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!