我已经制作了一个非常基本的PHP脚本来隔离我遇到的问题。该脚本只接收一些不相关的POST数据,然后在写入日志时延迟计数50次。
通常一分钟进入运行时脚本将从某处收到GET请求,该请求会中断对客户端的响应。为了排除客户端问题,我正在使用Chrome Advanced Restful客户端进行测试。请求总是来自我的IP(我已记录)。
可能导致此问题的原因以及如何解决?如果有人能帮我解决这个问题,我会非常感激,因为我不能为我的生活弄清楚。
这是脚本。注意开头的回声,宁静的客户端永远不会收到回应,因为杂散的GET响应总是会中断它:
<?php
echo "SCRIPT HAS FINISHED!";
$q = $_POST['q'];
$req=$_SERVER['REQUEST_METHOD'];
$ip = $_SERVER['REMOTE_ADDR'];
$agent = $_SERVER['HTTP_USER_AGENT'];
writelog("IP Logged: ".$ip);
writelog("User agent: " . $agent);
writelog("Post data: " . $q);
writelog("Request method: " . $req);
if ($q==""){
writelog ("MISFIRE!!!");
die;
}
writelog("*** Error check started ***");
for ($i = 1; $i <= 50; $i++) {
writelog ($i);
sleep(rand(2,20));
}
function writelog($towrite)
{
$tdate=date('d/m/Y H:i:s');
$file = 'log/testlog.txt';
$current = $towrite." --- ".$tdate."\n";
file_put_contents($file, $current, FILE_APPEND);
}
writelog("*** Error check ended ***");
?>
这是日志的典型结果。
在第7个条目之后看到有GET请求。
IP Logged: 86.31.**.99 --- 06/06/2014 10:45:57
User agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36 --- 06/06/2014 10:45:57
Post data: foobar --- 06/06/2014 10:45:57
Request method: POST --- 06/06/2014 10:45:57
*** Error check started *** --- 06/06/2014 10:45:57
1 --- 06/06/2014 10:45:57
2 --- 06/06/2014 10:46:05
3 --- 06/06/2014 10:46:12
4 --- 06/06/2014 10:46:19
5 --- 06/06/2014 10:46:33
6 --- 06/06/2014 10:46:37
7 --- 06/06/2014 10:46:41
IP Logged: 86.31.**.99 --- 06/06/2014 10:46:44
User agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36 --- 06/06/2014 10:46:44
Post data: --- 06/06/2014 10:46:44
Request method: GET --- 06/06/2014 10:46:44
MISFIRE!!! --- 06/06/2014 10:46:44
8 --- 06/06/2014 10:47:00
9 --- 06/06/2014 10:47:20
10 --- 06/06/2014 10:47:24
这是来自restful客户端的响应标头:
Date: Fri, 06 Jun 2014 10:46:44 GMT
Server: Apache
Content-Length: 20
Connection: close
Content-Type: text/html
此GET请求来自何处以及如何阻止它干扰我的脚本?