简体   繁体   English

轮询Apache服务器无响应

[英]Polling Apache server not responding

The apache server I am using to develop my system will not respond to request while the scripts that control the polling of messages is being run. 运行用于控制消息轮询的脚本时,用于开发系统的apache服务器不会响应请求。 This only happends on a domain level meaning that I can send an http request to any other apps hosted localy and get a response. 这仅在域级别发生,这意味着我可以向本地托管的任何其他应用发送http请求并获得响应。 When I do eventually get a response from this its about a minute later. 当我最终从中得到答复时,大约一分钟后。

Here is the Js 这是Js

window.fetch_messages = function ()
{
    var last_message = $("div.message:last").attr('data-ai_id');
    var last_message_status = $("p.message_status:last").text();
    var project_id = getParameterByName('project-id');

    $.ajax({
            url:'/project_messages',
            type:'POST',
            data:{ project_id:project_id, latest_message:last_message, status:last_message_status },
            timeout:50000,
            async: true,
            success:new_messages, // This upon completion also resends the request
            error:function(data){ console.log(data); setTimeout(fetch_messages(),50000); }
    });

}; // When On the page that uses this I call this function to start polling

Here is the server side code 这是服务器端代码

do 
{
    // Check for status change
    $status_change = $this->mentor_model->query_status($this->project_id, $this->last_message_id, $this->last_message_status, $_SESSION['user']); 

    // Check for new messages
    $messages = $this->mentor_model->query_messages($this->project_id, $this->last_message_id); 

    // If there is a  status update or new message.
    if($messages || $status_change)
    break;

    usleep(1000000);
}
while(empty($messages) && empty($status_change));

echo json_encode(array("messages"=>$messages, "status"=>$status_change));
exit;

While this action is being run The server takes a long time to handle any request weather it be a GET, POST or another AJax request. 在运行此操作时,服务器需要很长时间来处理任何请求,无论是GET,POST还是其他AJax请求。 Iv also tried changing both code sets to no avail as long as its long polling, the server will take a long time to handle. iv还尝试将这两个代码集更改为无用,只要它进行长时间轮询,服务器将需要很长时间来处理。

Do I have this wrong or is there some apache setting I'm suppose to change. 我是否有此错误,或者我想更改一些Apache设置? Using xamp on windows 8.1 also tried wamp with no change 在Windows 8.1上使用Xamp还尝试了Wamp,但未做任何更改

Thanks to steven for this. 感谢史蒂文。 Ansewer taken straight from the source of php manual page for session_write_close(); Ansewer直接从php手册页的源代码获取session_write_close();

You can have interesting fun debugging anything with sleep() in it if you have a session still active. 如果会话仍处于活动状态,则可以使用sleep()调试任何内容,从而获得有趣的乐趣。 For example, a page that makes an ajax request, where the ajax request polls a server-side event (and may not return immediately). 例如,发出ajax请求的页面,其中ajax请求轮询服务器端事件(并且可能不会立即返回)。

If the ajax function doesn't do session_write_close(), then your outer page will appear to hang, and opening other pages in new tabs will also stall. 如果ajax函数不执行session_write_close(),则您的外部页面似乎将挂起,并且在新标签页中打开其他页面也将停止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM