title: Make PHP socket_connect timeout
body: <p>I have a small application I created to analyze the network connection. It runs from a browser and connects to a local PHP/Apache server. It then asks PHP to send a ping packet through a raw socket. THe problem is that if the host I am trying to ping isn't alive or won't answer to pings, we never get an answer from the server.</p>
  
  <p>I beleave the socket request lives until apache is restarted. I have been getting mixed results from my application lately and I am blaming apache using too many sockets. Currently I have set the AJAX call's timeout and I was happy with it. But I really need to make PHP do the timeouting so that I won't have 500,000 sockets open to an unreachable host.</p>
  
  <p>Some sample code:</p>
  
  <pre><code>$sockconn = @socket_connect($socket, $target, null);
  if(!$sockconn)
  {
      $raw['error'] = socket_strerror(socket_last_error());
      $raw['status'] = false;
      return $raw;
  }
  </code></pre>
  
  <p>This is the function that won't timeout. I need to get it to timeout. Also PHP script execution time DOES NOT affect sockets.</p>
  
  <p>I am clueless.</p>