Background tasks in PHP: pinging

A long time ago, Ivan looked at executing background tasks in PHP after the actual request by the browser was over. He explained that it disappeared in PHP 4.1, but should be (and is) part of PHP 4.3.1.
I modified b2edit.php to use the register_shutdown_function to call the pingWeblogs, and pingBlogs functions:
From (line 100 of b2edit.php):

pingCafelog($cafelogID, $post_title, $post_ID);


pingCafelog($cafelogID, $post_title, $post_ID);
register_shutdown_function( "pingWeblogs" );
register_shutdown_function( "pingBlogs" );

This probably won’t work if you’re using PHP 4.1, so test it after you make the change! Does it make posting to b2 faster? I’m not sure. I don’t think those functions “disconnect” from the browser completely. Of course, I could be mistaken and the delay could be in another part of the code! I don’t honestly know.
Final note – I made a quick optimization by removing the call to rss_update(). That function creates the b2rss.xml file. Since we don’t use that file (use b2rss2.php or b2rdf.php instead!), the function call isn’t required!

By Donncha

Donncha Ó Caoimh is a software developer at Automattic and WordPress plugin developer. He posts photos at In Photos and can also be found on Twitter.

Leave a Reply