Skip to content

Instantly share code, notes, and snippets.

@smhmic
Created December 13, 2012 17:01
Show Gist options
  • Save smhmic/4277961 to your computer and use it in GitHub Desktop.
Save smhmic/4277961 to your computer and use it in GitHub Desktop.
asynch-requestable php script. Copied from -nathan's comment on http://petewarden.typepad.com/searchbrowser/2008/06/how-to-post-an.html
<?php
/// script can run forever..
set_time_limit(0);
/// tell the client the request has finished processing
header('Connection: close');
@ob_end_clean(); #seems to complain a lot w/o the @
/// continue running once client disconnects
ignore_user_abort();
ob_start();
/* this is where regular request code runs..
* in this case, we'll probly just send off some
* sort of 'succeeded' response
*/
echo handleRequest(); # <- example 'normal' request code..
/// clean things up on the server, and respond to the client
$iSize = ob_get_length();
header("Content-Length: $iSize");
@ob_end_flush();
flush();
session_write_close();
/* this is where code that will be executed
* after the client disconnects will run
*/
handleAsync();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment