One morning in October we deployed a new version of one of our plugins. A few minutes later the site stopped answering. Not slow: stopped. Every PHP worker was busy, every new request queued behind them, and the only way out was restarting PHP.
The cause was four lines of code that almost every WordPress plugin has in some form:
add_action ( 'plugins_loaded' , function ( ) { if ( get_option ( 'my_plugin_db_version' ) !== '1.30.0' ) { my_plugin_create_tables ( ) ; // dbDelta, ALTER TABLE update_option ( 'my_plugin_db_version' , '1.30.0' ) ; } } ) ;
Enter fullscreen mode
Exit fullscreen mode
This post is about why that pattern is dangerous on a busy site, and the small runner we replaced it with. We run Transtoyou , an online health platform in 14 languages on one WordPress multisite, so a broken deploy means patients who cannot reach a doctor. But nothing here is specific to health.…