send header and close connection, but still run additional code
| From: | Antony Nguyen | Date: | Wed, 23 Apr 2003 01:06:53 +0000 |
| Subject: | send header and close connection, but still run additional code | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-144933@lists.php.net to get a copy of this message | ||
Hello,
I am working on a redirect script that sends the client a "Location"
header via the header() function. This script needs to stay alive and do
additional work after the header is sent (database work, log crunching,
etc).
Basically, the code looks like:
<?php
header("Location: http://remote.site/url");
## Do my intensive work here...
...
...
?>
The problem with this is that PHP doesn't actually send the modified
header until the entire script is finished. If I add a sleep(20) command
after the header, it takes 20 seconds longer for my browser to see the redirect!
I've tried a couple different things with no success:
- added a call to ob_end_flush(); after the header() call
- added "Connection: close" to the header
In PERL, I would turn off output buffering by setting the special variable
$| to a non-zero value. I would then be able to send a raw header request
to the client, and then have the script finish the work in the
background.
Is this possible with PHP?
Thanks,
Tony