Skip to content

Instantly share code, notes, and snippets.

@harishanchu
Last active December 25, 2015 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harishanchu/6933978 to your computer and use it in GitHub Desktop.
Save harishanchu/6933978 to your computer and use it in GitHub Desktop.
php asynchronous requests
<?php
/**
* With following script you can make multiple php requests in a same session asynchronously
*/
// script can run forever..
set_time_limit(0);
// tell the client the request has finished processing
header('Connection: close');
@ob_end_clean();
// 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
*/
# <- 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
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment