Tracking long running php scripts externally

#3
[eluser]CroNiX[/eluser]
That's part of it, but I was really wanting to spawn a new process (fork) so this script can process several things at once in parallel instead of sequentially. It also doesn't send any output to the user until the entire script finishes. What it does do is allow the user to navigate away from the page and have the script finish in the background.

This gets closer (sends output immediately) but still processes sequentially.
Code:
//Unlimited time and ignore user abort
ignore_user_abort(TRUE);
set_time_limit(0);

//capture the output
ob_start();
echo json_encode($data);

//Send json header along with no-cache
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
  
//Get length of (json) output and terminate connection to browser to allow background process to continue
header("Content-Length: " . ob_get_length());
header('Connection: close');
  
//Send it all out, we're done
ob_end_flush();
ob_flush();
flush();

//Now browser has the output and script can continue...
//rest of long running code here...


Messages In This Thread
Tracking long running php scripts externally - by El Forum - 11-24-2012, 02:28 PM
Tracking long running php scripts externally - by El Forum - 11-24-2012, 03:18 PM
Tracking long running php scripts externally - by El Forum - 11-26-2012, 10:49 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.