Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    What could be sending GET requests to my PHP script?

    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 Code:
    <?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$currentFILE_APPEND);

    writelog("*** Error check ended ***");
    ?>
    And here's a typical result of the log.

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


    Code:
    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
    ... the original instance of the script will continue running until it reaches 50 but the client won't receive the response, it only receives the response from the GET interruption.

    This is the response headers from the restful client:

    Code:
    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?

  • #2
    Regular Coder
    Join Date
    Sep 2002
    Posts
    462
    Thanks
    0
    Thanked 20 Times in 20 Posts
    try changing your sleep method from a random to specific setting like 1 or 2 and see if it still happens.

    of course it may be easier to check by creating a string of data then entering it into the file.

    Code:
    <?php
    echo "SCRIPT HAS FINISHED!";
    
    
     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);
    } 
    
    $q = $_POST['q'];
    
    $req=$_SERVER['REQUEST_METHOD'];
    $ip = $_SERVER['REMOTE_ADDR'];
    $agent = $_SERVER['HTTP_USER_AGENT'];
    
    $LineEnding = "\n";
    
    $Str  = '';
    $Str .= 'IP Logged:' .$ip.$LineEnding;
    $Str .= 'User Agent: ' .$agent.$LinEnding;
    $Str .= 'Post Data: '.$q.$LineEnding;
    $Str .= 'Request Method: '.$req.$LineEnding;
    
    if ($q==""){
    $Str .= 'MISFIRE!!!'.$LineEnding;
    writelog($Str);
    exit;
    }
    
    $Str .= '*** Error check started ***'.$LineEnding;
    
    for ($i = 1; $i <= 50; $i++) {
    $Str .= $i.$LineEnding;
    }
    
    $Str .= '"*** Error check ended ***';
    writelog($Str);
    
    ?>
    Last edited by c1lonewolf; 06-06-2014 at 10:33 PM.
    NO Limits!! DHCreationStation.com
    ------------------------------------------------------------
    For projects using MediaTypes (MIMETypes) visit E-BAM.net -(updated weekly)

    Broken items wanted for tinkerin'! PostItNow@BrokenEquipment.com
    Global Complaint Dept.

  • #3
    Regular Coder
    Join Date
    Oct 2004
    Posts
    363
    Thanks
    0
    Thanked 18 Times in 18 Posts
    If must be how are you calling the PHP script. How are you calling it? The browser or JavaScript or other script is making two separate calls to the script (first POST then GET). (If you used a separate file for each request it would not be in the same file.)

    For example, if you were using AJAX the POST request/response might be getting overwritten by a different GET request because the same variable names are used.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •