【发布时间】:2012-04-15 18:02:45
【问题描述】:
我的网站上有一个使用 jquery ajax 函数调用的 PHP 脚本。基本上,用户在我的网站上按下一个按钮,它会向这个 PHP 脚本发送一个 ajax 调用,然后使用 proc_open 在我的服务器上调用一个 python 脚本。当我在 Firefox 中测试它时,这一切都很好,但是当我在其他浏览器(chrome、safari、mobile safari)中测试它时,脚本无限循环。我还尝试直接调用 PHP 脚本(通过将 url 粘贴到浏览器中)来检查它是否在我的 jquery 中存在无限循环,并且我得到相同的结果(在 ff 中运行良好,但在所有其他浏览器中运行无限循环)。据我了解,PHP 代码在服务器端执行,然后将输出发送到客户端浏览器,所以我无法弄清楚为什么脚本只在 firefox 中运行。我还尝试通过 SSH 连接到我的服务器并从命令行运行 python 脚本,它运行良好,所以我认为 python 脚本没有问题。
这是我的 php 代码:
<?php
require('../include/constants.php');
session_start();
if(!isset($_SESSION['logged_in'])||!$_SESSION['logged_in'])
{
header('location:../login.php');
}
$link = mysql_connect(DB_SERVER,DB_USER,DB_PASSWORD);
mysql_select_db(DB_NAME);
$q = "SELECT `cupiduser`,`cupidpass` FROM `users` WHERE `email`='".$_SESSION['email']."' LIMIT 1;";
$result = mysql_query($q);
$row = mysql_fetch_assoc($result);
$minage = $_GET['min'];
$maxage = $_GET['max'];
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("pipe", "w") // stderr is a file to write to
);
$cmd = 'python ~/data/users/demo2.py "'.$row['cupiduser'].'" "'.$row['cupidpass'].'" "'.$minage.'" "'.$maxage.'"';
$proc = proc_open($cmd, $descriptorspec, $pipes);
if(is_resource($proc))
{
fclose($pipes[0]);
$count = fread($pipes[1], 512);
fclose($pipes[1]);
fclose($pipes[2]);
$exit = proc_close($proc);
}
echo trim($count);
ob_end_flush();
ob_flush();
flush();
ob_start();
?>
python 代码只是运行一些计算,然后在最后返回一个如下所示的数字:
print str(count)
【问题讨论】:
-
Chrome 运行时会说什么?在 chrome 中打开页面并检查开发者控制台是否有错误
-
jquery 可能存在问题。我们可以提供一些代码吗?
-
无限循环是什么意思?你的意思是你反复发送ajax请求。你的服务器挂了吗?如果还没有,请在 Chrome 中打开网络标签。可能是js...
-
如果您的代码中没有循环,您如何获得“无限循环”=)?也许你有重定向循环?
-
问题不在于 JQuery,我尝试通过转到所有浏览器中的实际 URL(绕过 jquery)来运行 php 脚本并得到相同的结果。
标签: php python firefox google-chrome infinite-loop