title: Detect android java client connection timeout from PHP
body: <p>I'm connecting from an android device using java to a server running PHP using DefaultHttpClient.</p>
  
  <p>One test I am doing is to check that the java code gracefully handles itself if the server takes to long in sending data back. If it does take to long it disconnects and retries.</p>
  
  <p>Currently I have setup the connection timeout to 3 seconds by: </p>
  
  <pre><code>HttpConnectionParams.setSoTimeout(httpParameters, 3000);
  </code></pre>
  
  <p>On the server the PHP script is sleeping for 10 seconds:</p>
  
  <pre><code>sleep(10);
  </code></pre>
  
  <p>The java code works, if the script takes longer than 3 seconds then it throws a java.net.SocketTimeoutException and then retries again after a small amount of time.</p>
  
  <p>The PHP script continues to run which is <strong>not</strong> what I want. I've tried testing using connection_aborted straight after the sleep function but it does not catch the client disconnect which has already happened.</p>
  
  <pre><code>ignore_user_abort(true);
  sleep(10);
  print "black hole";
  flush();
  if(connection_aborted()!=0){
          // You would think this works but it does not.
  }
  </code></pre>
  
  <p>Whats the recommended way to handle this?</p>