Last active
December 25, 2015 06:39
-
-
Save harishanchu/6933978 to your computer and use it in GitHub Desktop.
php asynchronous requests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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