| PHP Performance |
 |
2012-02-14 |
 |
 |

7 |
 |
 |
Check for open() syscalls
~> grep open strace.out
open("/var/www/wp1/wp-load.php", O_RDONLY) = 29
open("/var/www/wp1/wp-config.php", O_RDONLY) = 29
open("/var/www/wp1/wp-settings.php", O_RDONLY) = 29
open("/var/www/wp1/wp-includes/wp-db.php", O_RDONLY) = 29
open("/var/www/wp1/wp-includes/cache.php", O_RDONLY) = 30
open("/var/www/wp1/wp-includes/pomo/translations.php", O_RDONLY) = 30
open("/var/www/wp1/wp-includes/pomo/entry.php", O_RDONLY) = 30
open("/var/www/wp1/wp-includes/pomo/streams.php", O_RDONLY) = 30
open("/var/www/wp1/wp-includes/default-widgets.php", O_RDONLY) = 30
open("/var/www/wp1/wp-includes/default-embeds.php", O_RDONLY) = 30
open("/var/www/wp1/wp-includes/template-loader.php", O_RDONLY) = 30
open("/var/www/wp1/wp-content/themes/default/header.php", O_RDONLY) = 30
open("/var/www/wp1/wp-content/themes/default/sidebar.php", O_RDONLY) = 30
open("/var/www/wp1/wp-content/themes/default/footer.php", O_RDONLY) = 30
open("/var/www/wp1/wp-content/themes/default/style.css", O_RDONLY) = 29
open("/var/www/wp1/wp-content/themes/default/images/kubrickbgcolor.jpg", O_RDONLY) = 29
open("/var/www/wp1/wp-content/themes/default/images/kubrickbg-ltr.jpg", O_RDONLY) = 29
open("/var/www/wp1/wp-content/themes/default/images/kubrickheader.jpg", O_RDONLY) = 29
open("/var/www/wp1/wp-content/themes/default/images/kubrickfooter.jpg", O_RDONLY) = 29
Conditional config include in wp-load.php
<?php
if ( file_exists( ABSPATH . 'wp-config.php') ) {
/** The config file resides in ABSPATH */
require_once( ABSPATH . 'wp-config.php' );
} elseif ( file_exists( dirname(ABSPATH) . '/wp-config.php' ) && ! file_exists( dirname(ABSPATH) . '/wp-settings.php' ) ) {
/** The config file resides one level above ABSPATH but is not part of another install*/
require_once( dirname(ABSPATH) . '/wp-config.php' );
} else {
// A config file doesn't exist
// Set a path for the link to the installer
if (strpos($_SERVER['PHP_SELF'], 'wp-admin') !== false) $path = '';
else $path = 'wp-admin/';
// Die with an error message
require_once( ABSPATH . '/wp-includes/classes.php' );
require_once( ABSPATH . '/wp-includes/functions.php' );
require_once( ABSPATH . '/wp-includes/plugin.php' );
$text_direction = /*WP_I18N_TEXT_DIRECTION*/"ltr"/*/WP_I18N_TEXT_DIRECTION*/;
wp_die(sprintf(/*WP_I18N_NO_CONFIG*/"There doesn't seem to be a <code>wp-config.php</code> file. I need this before we can ge
t started. Need more help? <a href='http://codex.wordpress.org/Editing_wp-config.php'>We got it</a>. You can create a <code>wp-config
.php</code> file through a web interface, but this doesn't work for all server setups. The safest way is to manually create the file.
</p><p><a href='%ssetup-config.php' class='button'>Create a Configuration File</a>"/*/WP_I18N_NO_CONFIG*/, $path), /*WP_I18N_ERROR_TI
TLE*/"WordPress › Error"/*/WP_I18N_ERROR_TITLE*/, array('text_direction' => $text_direction));
}
?>
Replace with
<?php
include './wp-config.php';
?>
Conditional did-header check in wp-blog-header.php
<?php
#if ( !isset($wp_did_header) ) {
$wp_did_header = true;
require_once( dirname(__FILE__) . '/wp-load.php' );
wp();
require_once( ABSPATH . WPINC . '/template-loader.php' );
#}
?>
require_wp_db() call in wp-includes/functions.php
<?php
function require_wp_db() {
global $wpdb;
if ( file_exists( WP_CONTENT_DIR . '/db.php' ) )
require_once( WP_CONTENT_DIR . '/db.php' );
else
require_once( ABSPATH . WPINC . '/wp-db.php' );
}
?>
Don't call require_wp_db() from wp-settings.php
<?php
#require_wp_db();
require './wp-includes/wp-db.php';
Hardcode built-in wp cache in wp-settings.php
<?php
require './wp-includes/cache.php';
Remove conditional require logic from wp_start_object_cache
<?php
function wp_start_object_cache() {
global $_wp_using_ext_object_cache;
$first_init = false;
$_wp_using_ext_object_cache = false;
static $first_init = true;
# if ( ! function_exists( 'wp_cache_init' ) ) {
# global $_wp_using_ext_object_cache;
# if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
# require_once ( WP_CONTENT_DIR . '/object-cache.php' );
# $_wp_using_ext_object_cache = true;
# } else {
# require_once ( ABSPATH . WPINC . '/cache.php' );
# $_wp_using_ext_object_cache = false;
# }
# $first_init = true;
# }
...
Check again
~> grep open strace2.out
open("/var/www/wp2/wp-includes/pomo/translations.php", O_RDONLY) = 30
open("/var/www/wp2/wp-includes/pomo/entry.php", O_RDONLY) = 30
open("/var/www/wp2/wp-includes/pomo/streams.php", O_RDONLY) = 30
open("/var/www/wp2/wp-includes/default-widgets.php", O_RDONLY) = 30
open("/var/www/wp2/wp-includes/default-embeds.php", O_RDONLY) = 30
open("/var/www/wp2/wp-includes/template-loader.php", O_RDONLY) = 30
open("/var/www/wp2/wp-content/themes/default/header.php", O_RDONLY) = 30
open("/var/www/wp2/wp-content/themes/default/sidebar.php", O_RDONLY) = 30
open("/var/www/wp2/wp-content/themes/default/footer.php", O_RDONLY) = 30
open("/var/www/wp1/wp-content/themes/default/style.css", O_RDONLY) = 29
open("/var/www/wp1/wp-content/themes/default/images/kubrickbgcolor.jpg", O_RDONLY) = 29
open("/var/www/wp1/wp-content/themes/default/images/kubrickbg-ltr.jpg", O_RDONLY) = 29
open("/var/www/wp1/wp-content/themes/default/images/kubrickheader.jpg", O_RDONLY) = 29
open("/var/www/wp1/wp-content/themes/default/images/kubrickfooter.jpg", O_RDONLY) = 29
We just have translations, plugins and themes left here now. We could hardcode these as
well, but then we start to lose the main characteristics of Wordpress.