making bbPress (and WordPress) work better!

WP performance

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.

Javascript sort of has this method using DEFER in the script tag which I take advantage often (it causes the external script not to be loaded/executed until /body finishes (not all browsers support it).

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” ?


measuring WordPress performance

At some point you might get curious about how fast or slow WordPress is actually running, especially after a few strange reports that 2.0.4 is running slower.

I had tinkered with Jerome’s Query Diagnostics plugin:
http://vapourtrails.ca/wp-plugins (at the bottom of the page)

but on the WordPress IRC I just learned about
libertus’ interesting “performance probe” plugin
http://libertini.net/libertus/wordpress-plugins/performance-probe/
which looks even more fascinating… (also see his other posts here and here)

added: apparently I can’t use his plugin (as many people on shared servers will discover) since my PHP was not compiled with the “–enable-memory-limit configuration option” – there is also a php function called “memory-get-peak-usage” which might be helpful to some.

Be sure to see all the links on the right hand side on my main page here for more performance and development plugins/info on WordPress.

By the way I made a subtle enhancement to Jerome’s output, the code follows below the break:
(more…)