title: PHP fsockopen script times out over ajax but completes almost instantly in commandline
body: <p>I'm trying to make a webpage on another server where the status of my own server will be displayed.
  I am using an AJAX-request like this:</p>
  
  <pre><code>$.ajax({
      url: 'status.php',
      data: {ip:address},
      success: function(data){
          //do stuff
      },
      dataType:'text'
  });
  </code></pre>
  
  <p>to send the ip-address of the server to the status.php script, which looks like this:</p>
  
  <pre><code>if($_GET['ip']){
      $ip = $_GET['ip'];
      //var_dump($_GET['ip']); 
      $port = 64738;
      $up = fsockopen("tcp://$ip", $port, $errno, $errstr, 30);   
      if($up){   
          echo "success";   
      } 
      else{ 
          echo "failure";
  } 
  </code></pre>
  
  <p>I rewrote the script a bit like this:</p>
  
  <pre><code>$ip = "&lt;ip_of_my_server&gt;"; 
      $port = 64738;
      $up = fsockopen("tcp://$ip", $port, $errno, $errstr, 5);   
      if($up){   
          echo "success";   
      } 
      else{ 
          echo "failure";
      }
  </code></pre>
  
  <p>so I can use it from the command line, for testing purposes.</p>
  
  <p>This second script works perfectly and almost instantly from the command line and outputs "success".</p>
  
  <p>But with the AJAX request, the first and second script will both give errornr. 110 (connection timed out) for the fsockopen output after 30 seconds and thus output "failure".</p>
  
  <p>What could be reason?
  Thanks in advance!</p>