What you could do is put your 'lengthy process' in a shutdow function (register_shutdown_function()), and just do the header.

There is actually even a simpler way to do this, but it's not advised:

-------------------------
first
<?php
@set_time_limit(0); // Make sure there is no limit
ob_start(); // Start output buffering

if(array_key_exists('secondrun',$_GET)) {
print "Processing complete!";
exit();
}else{
header("Location:http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}?secondrun=1");
ob_flush(); // This sends the output to your browser
ignore_user_abort(true);// Makes sure the script continues...
... // Lengthy process here
}
?>
-------------------------

Basicly, what it does here, is force the engine to flush the output (the redirect) to your browser, next,
because the set_time_limit is set to 0 (unlimited), your script still goes on... While you can follow the other link.

The ignore_user_aboort(true), makes sure the server continues till the script finishes. Otherwise it would kill it as soon as you'd press stop on your browser :)

Hope that helps,
- Tularis

Leif K-Brooks wrote:
I need a way to keep the script running on the server, but control to the user. I'm doing some lengthy processes on the server, and it seems stupid to keep the user waiting pointlessly. I'm trying to do something like:
<?php

header("Location: http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}?secondrun=1");
//Do long processing here
?>
but it waits till the long processing is done, and then redirects. Is there another way to do this?


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to