title: Timing out a photo upload if it's taking too long
body: <p>I'm creating a photo booth app where users can share photos they've taken to their Facebook account. Mostly, it's working very well. I'm using AJAX to post to this PHP page:</p>
  
  <p>
  
  <pre><code>$appID = "#####";
  $appSecret = "#####";
  $accessToken = $_POST['accessToken'];
  $filePath = $_POST['imagePath'];
  $message = $_POST['message'];
  
  // Initialize the SDK
  $facebook = new Facebook(array(
      'appId' =&gt; $appID,
      'secret' =&gt; $appSecret,
      'fileUpload' =&gt; true,
      'cookie' =&gt; true
  ));
  
  $facebook-&gt;setAccessToken($accessToken);
  
  // Upload the photo
  $response = $facebook-&gt;api("/me/photos", "post", array(
      'message' =&gt; $message,
      'image' =&gt; '@' . $filePath
  ));
  
  echo json_encode($response);
  </code></pre>
  
  <p>If I get back a post ID from Facebook in the response, my Javascript shows a success message. If I get a response back without a post ID, it shows an error message. Occasionally, whether it's Facebook being slow or the internet cutting out or another factor outside of my control, the request to Facebook keeps processing and I never get a response back at all.</p>
  
  <p>I would like to create some kind of "still working..." message partway through the upload if it's taking a long time, followed by a "We're sorry, but your photo couldn't be uploaded. Please refresh the page and try again" if it takes too long. I know I can easily create a timeout on a jQuery.ajax request, but the problem is (as far as my understanding goes) even if it times out and the error callback is executed, the request is still going on the server. If for some reason it takes longer than my timeout to upload the original photo, when the user refreshes the page and uploads successfully they'll have a duplicate.</p>
  
  <p>I've come up with a few hypothetical solutions to this but am not sure how to implement any of them.</p>
  
  <p>1) Cancel the upload process server-side after a certain amount of time (I'm fairly certain this isn't possible) and show an error
  2) Check for a duplicate photo before uploading (it seems that this wouldn't work with a really slow upload process)</p>
  
  <p>And so I'm left with the only solution of hoping that the timing out process never finishes. This strikes me as unreliable and could result in a few duplicates. At the same time, when I've tried to wait out the upload it's always taken longer than I had the patience for.</p>
  
  <p>Any ideas for solving this problem?</p>