I'm accountable for the after sales part of an API, designed in PHP, that is mainly utilized by a Expensive client. What goes on at this time is: the Expensive client constitutes a call, the after sales loads the required data, does any necessary processing and publish processing, logging and caching after which returns the end result towards the client.

What I must have happen is return the information towards the client as quickly as possible, close the bond, after which do everything the client does not need to worry about. This might result in the API appear a lot more responsive. Following a suggestions here:


really works, with the exception that I must switch off gzip encoding to be able to have great results, which is not very practical. We use mod_deflate in apache, so an answer that actually works with that would be amazing, however i would also think about a different approach to gzip our content if that's necessary.

It appears like there must be a method to let Apache know "I have sent all of you the information I am likely to send," however i can't appear to locate anything like this.

For individuals wondering, yes I'm able to flush the outcomes early, however the Expensive client won't process them before the connection is closed.

You could try breaking it into two pages.

In page one, perform the necessary processing, then load the 2nd page via curl, and die().

That will cause page one to accomplish and close, in addition to the second page processing.


The First Page:


// Do stuff

// Post or get second page...

// Send Data to client


Page 2:


// Do other stuff....


See http://www.php.internet/curl

There is a type of hack to get this done by placing the code you need to execute following the connection shuts inside a callback method registered via to register_shutdown_function();

@Theo.T because the comment system mangled the garbage from my code, I am posting it here:

No luck. The next prints the extra garbage and takes the entire execution time for you to close the bond when utilizing mod_deflate:

function sleepLongTime() { 
    print "you can't see this";
header("Connection: close\r\n");
echo ('Text user will see');
header("Connection: close");
header("Content-Length: " .(strlen($stream)+256));

echo $stream;
echo(str_repeat(' ',256));


this can tell the consumer to shut the bond once all $stream is received . but take care not to echo anything prior to the header part u know :p

if you're delivering binary data (swf) you will need to get rid of the '+256' and echo(str_repeat(' ',256)); however in this situation the code 'might' fail when the data sent is l'ensemble des than 256 bytes .