Continuing execution after page is sent down
Posted: Thu May 20, 2004 10:45 am
I posted a topic a while back regarding continuing execution of a php script after all information has been sent down to a client. It's nowhere to be found here, so I'm guessing that it was lost when the forum database crashed. Anyway, I found a solution so I figured that I would share it with everyone.
What I ended up doing was adding a background image in my style file on my body tag, like this:
Then in somescript.php, you do your processing and send down a blank image file (or you could send down a real background image if you like).
Here's how I did it
Note that somescript.php is called when the client's browser reads the stylesheet and requests the background image from your server.
There are a couple of disadvantages to this, as it requires that a user have css and images enabled in their browser. Also, if you're using it for running a task at specified intervals like I am, the task will not get run unless someone is actively browsing the site. That being said, it works for my purposes so it might work for yours.
What I ended up doing was adding a background image in my style file on my body tag, like this:
Code: Select all
<style>
body
{
/*other body styles here */
background-image : url(somescript.php);
}
</style>Here's how I did it
Code: Select all
<?php
//do processing up here that you don't need output from
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// always modified
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1 no caching
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0 no caching
header("Pragma: no-cache");
// tell it that this is a gif
header("Content-Type: image/gif");
readFile("images/blank.gif");
?>There are a couple of disadvantages to this, as it requires that a user have css and images enabled in their browser. Also, if you're using it for running a task at specified intervals like I am, the task will not get run unless someone is actively browsing the site. That being said, it works for my purposes so it might work for yours.