Possible Duplicate:
close a connection early
I'm looking to accomplish something along the lines of this:
- User requests
foo.html
- Page starts TCPIP socket and HTTP session, echos request header information
- Page echos content for the file
- Page closes socket, user has file, everyone's happy, no more HTTP transactions going on.
- Function FooBar() gets invoked which... adds numbers, sends an email, updates a database, or some other task that doesn't block output of the page to the user.
In concept, my pseudo-PHP code might look like:
<?php
//Send content to the user
echo "Hello world!!";
//This terminates the script,
//I simply want to close the
//HTTP part without terminating
exit();
//That only took a few milliseconds
//Send an email to someone
//containing a sum of numbers
//in the Fibonacci sequence
//This task might take minutes to do.
mail(
"foo@example.com",
"Your sum is ready",
fibonacci(100)
);
But I don't see a clear way to do this as exit() terminates the script, and I don't see any methods that give me control over the HTTP socket.
I've seen close a connection early and it's an interesting answer however I'm looking to accomplish this in PHP 5.3 without output buffering and flushing.