0

When generating a page with PHP:

<?php
echo "Hello world";
// generate the HTML output
// HTML finished here
send_output_to_client();       // <-- how to do this?

perform_blocking_IO_operation();      // this can last 100 ms or more, this will not output anything anymore, 
                                      // only internal logging IO operations
?>

how to ask PHP to send the output to the client and don't wait for perform_blocking_IO_operation() to finish?

Since perform_blocking_IO_operation() can last 100 ms or more, I'd like to avoid this unnecessary waiting time for the client.

Basj
  • 41,386
  • 99
  • 383
  • 673
  • @Andy I thought `flush` or `ob_flush` would send data to client, but not close the HTTP connection. In my case, I would like to terminate the connection. – Basj Sep 20 '21 at 16:18
  • 100ms is 0.1s. not really going to be noticeable, surely... – ADyson Sep 20 '21 at 16:36
  • @ADyson Currently I serve the page to client in less than 100 ms; I don't want to double my page generation time because of this. – Basj Sep 20 '21 at 18:57

1 Answers1

1

Use flushing as mentioned above or RabbitMQ.

Tannenfels
  • 58
  • 4
  • 3
    Thank you and welcome to SO. Please elaborate with sample code and/or reference to documentation for this post to be a complete answer. – Basj Sep 20 '21 at 18:55
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-ask). – Community Sep 21 '21 at 00:33