This happens currently:
- Somebody requests https://www.example.com/
- My PHP script does it things, including many SQL queries, adding entries to an array for each.
- I run my "flush database log" function, which loops through that array and actually inserts the SQL queries into my database query log.
- The script finishes, thus sends all the HTML output to the client.
To prevent the client having to wait for longer than necessary, I would like this to happen instead:
- Somebody requests https://www.example.com/
- My PHP script does it things, including many SQL queries, adding entries to an array for each.
- The script sends the output to the client.
- I run my "flush database log" function, which loops through that array and actually inserts the SQL queries into my database query log.
- The script finishes, with the user not having to wait for the "flush database log" function, which is executed after the page has loaded from the user's perspective.
I know about the various flush
, ob_flush
, ob_flush_clean
and 800 different functions like that in PHP. I also know that the user comments and general online advice is full of warnings about how this either no longer works, or has never worked in the first place, apparently depending on the webserver/OS of the server.
Could I please, once and for all, get a 2020 answer to whether or not this works? And, if it does work, which function exactly am I supposed to use to "just send the webpage already; I'm done as far as the user is concerned"?