views:

55

answers:

4

I am using flash to call a PHP page that needs to do a bit of processing. Is it possible to let PHP continue processing but show a response anyway so flash doesn't stall waiting?

A: 

Use output control aka output buffering to do this. http://www.php.net/manual/en/function.ob-flush.php

hinghoo
A: 

You could try using flush()

As an example, try these two different pieces of code:

// without flush()
foreach ( range(1, 5) as $num ) {
    echo "Beep $num<br>";
    sleep(1);
}

// with flush()
foreach ( range(1, 5) as $num ) {
    echo "Beep $num<br>";
    flush();
    sleep(1);
}
kemp
A: 

You can close the connection within a registered function within register_shutdown_function if you do not need to wait for the processing to be over to output content (i.e., if you do not need to output anything related to the outcome of the processing you wish to do).

See : http://www.php.net/manual/en/features.connection-handling.php#93441

The reason to put it in a register_shutdown_function is that even if the client aborts the connection, the processing will keep on going to the very end.

Marc Trudel
+1  A: 

My answer from here:

You can send Connection:Close headers, which finishes the page for your user, but enables you to execute things "after page loads".

There is a simple way to ignore user abort (see php manual too):

ignore_user_abort(true);
Karsten