Is there a way to “DEFER” PHP code until after content is served?
So I’ve been thinking in weird ways about how WordPress and PHP works in general and why on a typical page the mysql queries may only take a quarter second but the rest of the PHP can take a half second or more…
Why can’t PHP/Wordpress defer some of the code execution until the HTML content is sent to the visitor? Are PHP sessions tied to the visitor being connected? Could WordPress have some kind of “post /html” queue where updates to databases and other stats are generated AFTER the visitor is sent what they requested?
Most of this idea is out of ignorance in how PHP works and how to identify parts of WordPress that could benefit from such a technique. I know you can use ob_flush to force any content waiting to be sent. But that’s useless if WordPress doesn’t have anything to do afterwards.
So in WordPress there is alot of little stuff that can’t wait until a pseudo-cron job and has to be done on a per-visitor basis, but not necessarily while they are waiting.
This whole idea requires more investigation/research but I think it has potential?
Any ideas from the php “pros” ?