PHP usleep()使我的所有PHP
我正在设置comet longpolling消息系统。PHP usleep()使我的所有PHP,php,jquery,ajax,Php,Jquery,Ajax,我正在设置comet longpolling消息系统。 使用jQuery和PHP。jQuery是我用于ajax的工具。 问题是,在ajaxto的php文件中,它在返回之前在while循环中等待数据,导致所有其他ajax请求在返回之前都处于挂起状态。在循环中,我调用usleep()。 似乎usleep正在冻结我的所有其他PHP,即使它们是独立的文件。有点奇怪。我如何解决这个问题?以下是comet php longpolling文件: <?php session_start(); if
使用jQuery和PHP。jQuery是我用于ajax的工具。
问题是,在ajaxto的php文件中,它在返回之前在while循环中等待数据,导致所有其他ajax请求在返回之前都处于挂起状态。在循环中,我调用usleep()。
似乎usleep正在冻结我的所有其他PHP,即使它们是独立的文件。有点奇怪。我如何解决这个问题?以下是comet php longpolling文件:
<?php
session_start();
if (empty($_SESSION['userID'])) {
echo json_encode(array("status" => "not-loggedIn"));
die();
}
if (empty($_GET['friendID'])) {
echo json_encode(array("status" => "friendID-invalid"));
die();
}
include("../../tools.php");
$html = getNewLiveChatMessages($_GET['friendID'], $_GET['messageID']);
if (!$html) {
$timeout = 2;
while ($timeout > 0) {
$html = getNewLiveChatMessages($_GET['friendID'], $_GET['messageID']);
if ($html) {
break;
}
$timeout--;
/* Wait 10 seconds */
usleep(10000000); /* In microseconds */
}
}
echo json_encode(array("status" => "success", "html" => $html));
?>
@CollinD是的,你说得对。我将删除我的评论。可能重复@CollinD是的,你是对的。我将删除我的评论。可能重复