What could be sending GET requests to my PHP scrip

2019-03-02 07:06发布

I've made a very basic PHP script to isolate a problem I'm having. The script just receives some irrelevant POST data and then counts up to 50 with a time delay while writing to a log.

Usually a minute into runtime the script will receive a GET request from somewhere which interrupts the response to the client. To rule out client issues I'm using Chrome Advanced Restful client to test. The request is always coming from my IP as well (I have that logged).

What could be causing this and how can I fix it? If anyone could help me crack this, I'd be very grateful because I can't for the life of me figure it out.

Here's the script. Note the echo at the beginning, the restful client never receives that because a stray GET response always interrupts it:

<?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 ***");
?> 

And here's a typical result of the log.

see after the 7th entry there is a GET request.

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

This is the response headers from the restful client:

Date: Fri, 06 Jun 2014 10:46:44 GMT 
Server: Apache 
Content-Length: 20 
Connection: close
Content-Type: text/html 

Where is this GET request coming from and how can I stop it interfering with my scripts?

标签: php rest
0条回答
登录 后发表回答