From: Nick Jenkins Date: Fri, 9 Feb 2007 05:36:56 +0000 (+0000) Subject: Prevent some unnecessary lstat system calls, generated by include or require directives. X-Git-Tag: 1.31.0-rc.0~54093 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/categories/modifier.php?a=commitdiff_plain;h=baaee13afceb192e1666f0613a6d70486c91b14f;p=lhc%2Fweb%2Fwiklou.git Prevent some unnecessary lstat system calls, generated by include or require directives. This can be done either by: * Using explicit full paths, using the $IP global for the installation directory full path, and then working down the tree from there. * Using explicit full paths, using the "dirname(__FILE__)" directive to get a full directory path for the includer file. * Occasionally removing the line altogether, and then for some files the inclusion is handled by the autoloader. For example, if the "extensions/wikihiero/wh_main.php" file does an include or require on "wh_list.php", then PHP does the following: * tries to open "wiki/wh_list.php", and fails. * tries to open "wiki/includes/wh_list.php", and fails. * tries to open "wiki/languages/wh_list.php", and fails. * tries to open "wiki/extensions/wikihiero/wh_list.php", and succeeds. So in this example, the first 3 calls can be prevented if PHP is told where the file is. Testing Method: On a Linux box, run these commands to attach strace to all the apache2 processes, and log their system calls to a temporary file, then generate some activity, and then stop the strace: ----------------------------------- rm /tmp/strace-log.txt strace -tt -o /tmp/strace-log.txt -p `pidof apache2 | sed 's/ / -p /g'` & php maintenance/fuzz-tester.php --keep-passed-tests --include-binary --max-runtime=3 > /tmp/strace-tests.txt killall -9 strace grep "No such file or directory" /tmp/strace-log.txt | sort -u ----------------------------------- Any failed file stats will be marked with: "-1 ENOENT (No such file or directory)". Also: * Strict Standards: Undefined offset: 230 in includes/normal/UtfNormal.php on line 637 * Strict Standards: iconv() [function.iconv]: Detected an illegal character in input string in languages/Language.php on line 776 [Note: Partial only - despite adding "//IGNORE", it still seems to be possible with some messed- up binary input to cause PHP 5.1.2's iconv() function to squeal like a stuck pig]. * Update one $fname variable (method belongs to HistoryBlobStub class). --- diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index fb7819cb74..1365be9eb9 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -313,7 +313,7 @@ function wfLoadAllExtensions() { # guaranteed by entering special pages via SpecialPage members such as # executePath(), but here we have to take a more explicit measure. - require_once( 'SpecialPage.php' ); + require_once( dirname(__FILE__) . '/SpecialPage.php' ); foreach( $wgAutoloadClasses as $class => $file ) { if( !( class_exists( $class ) || interface_exists( $class ) ) ) { diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 9c19758b29..22237ee5c2 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -18,9 +18,10 @@ $wgTotalViews = -1; $wgTotalEdits = -1; -require_once( 'LogPage.php' ); -require_once( 'normal/UtfNormalUtil.php' ); -require_once( 'XmlFunctions.php' ); +global $IP; +require_once "$IP/includes/LogPage.php"; +require_once "$IP/includes/normal/UtfNormalUtil.php"; +require_once "$IP/includes/XmlFunctions.php"; /** * Compatibility functions diff --git a/includes/HistoryBlob.php b/includes/HistoryBlob.php index 8d54e3697f..3ce4ffd94d 100644 --- a/includes/HistoryBlob.php +++ b/includes/HistoryBlob.php @@ -209,7 +209,7 @@ class HistoryBlobStub { /** @todo document */ function getText() { - $fname = 'HistoryBlob::getText'; + $fname = 'HistoryBlobStub::getText'; global $wgBlobCache; if( isset( $wgBlobCache[$this->mOldId] ) ) { $obj = $wgBlobCache[$this->mOldId]; diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index 5d0955fcab..c184c06dd0 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -534,7 +534,7 @@ class SpecialPage $this->mFunction = $function; } if ( $file === 'default' ) { - $this->mFile = "Special{$name}.php"; + $this->mFile = dirname(__FILE__) . "/Special{$name}.php"; } else { $this->mFile = $file; } diff --git a/includes/SpecialPrefixindex.php b/includes/SpecialPrefixindex.php index 73a67ee4c4..fc14d7ab3c 100644 --- a/includes/SpecialPrefixindex.php +++ b/includes/SpecialPrefixindex.php @@ -3,8 +3,6 @@ * @addtogroup SpecialPage */ -require_once 'SpecialAllpages.php'; - /** * Entry point : initialise variables and call subfunctions. * @param $par String: becomes "FOO" when called like Special:Prefixindex/FOO (default NULL) diff --git a/includes/SpecialRecentchanges.php b/includes/SpecialRecentchanges.php index 9ded0af414..98445754a9 100644 --- a/includes/SpecialRecentchanges.php +++ b/includes/SpecialRecentchanges.php @@ -7,7 +7,7 @@ /** * */ -require_once( 'ChangesList.php' ); +require_once( dirname(__FILE__) . '/ChangesList.php' ); /** * Constructor diff --git a/includes/SpecialUserrights.php b/includes/SpecialUserrights.php index 6668d0e9e7..30c7945bff 100644 --- a/includes/SpecialUserrights.php +++ b/includes/SpecialUserrights.php @@ -8,7 +8,7 @@ */ /** */ -require_once('HTMLForm.php'); +require_once( dirname(__FILE__) . '/HTMLForm.php'); /** Entry point */ function wfSpecialUserrights() { diff --git a/includes/SpecialWatchlist.php b/includes/SpecialWatchlist.php index 92ee4d617b..a9d61c06ba 100644 --- a/includes/SpecialWatchlist.php +++ b/includes/SpecialWatchlist.php @@ -7,7 +7,7 @@ /** * */ -require_once( 'SpecialRecentchanges.php' ); +require_once( dirname(__FILE__) . '/SpecialRecentchanges.php' ); /** * Constructor diff --git a/includes/Title.php b/includes/Title.php index cbba2198b4..c40b6e6d48 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -5,7 +5,7 @@ */ /** */ -require_once( 'normal/UtfNormal.php' ); +require_once( dirname(__FILE__) . '/normal/UtfNormal.php' ); define ( 'GAID_FOR_UPDATE', 1 ); diff --git a/includes/normal/UtfNormal.php b/includes/normal/UtfNormal.php index 7399f18e61..278c3cc903 100644 --- a/includes/normal/UtfNormal.php +++ b/includes/normal/UtfNormal.php @@ -225,7 +225,7 @@ class UtfNormal { static function loadData() { global $utfCombiningClass; if( !isset( $utfCombiningClass ) ) { - require_once( 'UtfNormalData.inc' ); + require_once( dirname(__FILE__) . '/UtfNormalData.inc' ); } } @@ -634,7 +634,11 @@ class UtfNormal { } if( isset( $utfCombiningClass[$c] ) ) { $lastClass = $utfCombiningClass[$c]; - @$combiners[$lastClass] .= $c; + if( isset( $combiners[$lastClass] ) ) { + $combiners[$lastClass] .= $c; + } else { + $combiners[$lastClass] = $c; + } continue; } } @@ -804,4 +808,4 @@ class UtfNormal { } } -?> \ No newline at end of file +?> diff --git a/languages/Language.php b/languages/Language.php index 7860676f19..47f169b675 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -22,7 +22,7 @@ if( !defined( 'MEDIAWIKI' ) ) { # Read language names global $wgLanguageNames; -require_once( 'Names.php' ); +require_once( dirname(__FILE__) . '/Names.php' ) ; global $wgInputEncoding, $wgOutputEncoding; @@ -772,7 +772,7 @@ class Language { function iconv( $in, $out, $string ) { # For most languages, this is a wrapper for iconv - return iconv( $in, $out, $string ); + return iconv( $in, $out . '//IGNORE', $string ); } // callback functions for uc(), lc(), ucwords(), ucwordbreaks() diff --git a/skins/Chick.deps.php b/skins/Chick.deps.php index a178a79195..54614c497a 100644 --- a/skins/Chick.deps.php +++ b/skins/Chick.deps.php @@ -9,5 +9,5 @@ if ( ! defined( 'MEDIAWIKI' ) ) die( 1 ); require_once('includes/SkinTemplate.php'); -require_once('MonoBook.php'); +require_once( dirname(__FILE__) . '/MonoBook.php' ); ?> diff --git a/skins/Chick.php b/skins/Chick.php index b346007aaf..9721900cb7 100644 --- a/skins/Chick.php +++ b/skins/Chick.php @@ -10,7 +10,7 @@ if( !defined( 'MEDIAWIKI' ) ) die( -1 ); /** */ -require_once('MonoBook.php'); +require_once( dirname(__FILE__) . '/MonoBook.php' ); /** * @todo document diff --git a/skins/MySkin.deps.php b/skins/MySkin.deps.php index ba00558b10..633ab5582c 100644 --- a/skins/MySkin.deps.php +++ b/skins/MySkin.deps.php @@ -9,5 +9,5 @@ if ( ! defined( 'MEDIAWIKI' ) ) die( 1 ); require_once('includes/SkinTemplate.php'); -require_once('MonoBook.php'); +require_once( dirname(__FILE__) . '/MonoBook.php' ); ?> diff --git a/skins/MySkin.php b/skins/MySkin.php index 8abc75b858..5331e21582 100644 --- a/skins/MySkin.php +++ b/skins/MySkin.php @@ -10,7 +10,7 @@ if( !defined( 'MEDIAWIKI' ) ) die( -1 ); /** */ -require_once('MonoBook.php'); +require_once( dirname(__FILE__) . '/MonoBook.php' ); /** * @todo document diff --git a/skins/Simple.deps.php b/skins/Simple.deps.php index 369f6b00ce..b7f1f5eb0f 100644 --- a/skins/Simple.deps.php +++ b/skins/Simple.deps.php @@ -9,5 +9,5 @@ if ( ! defined( 'MEDIAWIKI' ) ) die( 1 ); require_once('includes/SkinTemplate.php'); -require_once('MonoBook.php'); +require_once( dirname(__FILE__) . '/MonoBook.php' ); ?> diff --git a/skins/Simple.php b/skins/Simple.php index b180e801df..a9c0cc51c2 100644 --- a/skins/Simple.php +++ b/skins/Simple.php @@ -10,7 +10,7 @@ if( !defined( 'MEDIAWIKI' ) ) die( -1 ); /** */ -require_once('MonoBook.php'); +require_once( dirname(__FILE__) . '/MonoBook.php' ); /** * @todo document diff --git a/thumb.php b/thumb.php index c325d07a71..cad4a1b1d3 100644 --- a/thumb.php +++ b/thumb.php @@ -8,13 +8,13 @@ define( 'MW_NO_SETUP', 1 ); require_once( './includes/WebStart.php' ); wfProfileIn( 'thumb.php' ); wfProfileIn( 'thumb.php-start' ); -require_once( 'GlobalFunctions.php' ); -require_once( 'ImageFunctions.php' ); +require_once( './includes/GlobalFunctions.php' ); +require_once( './includes/ImageFunctions.php' ); $wgTrivialMimeDetection = true; //don't use fancy mime detection, just check the file extension for jpg/gif/png. -require_once( 'Image.php' ); -require_once( 'StreamFile.php' ); +require_once( './includes/Image.php' ); +require_once( './includes/StreamFile.php' ); // Get input parameters $fileName = isset( $_REQUEST['f'] ) ? $_REQUEST['f'] : ''; @@ -50,7 +50,7 @@ if ( is_file( $thumbPath ) && filemtime( $thumbPath ) >= filemtime( $imagePath ) // OK, no valid thumbnail, time to get out the heavy machinery wfProfileOut( 'thumb.php-start' ); -require_once( 'Setup.php' ); +require_once( './includes/Setup.php' ); wfProfileIn( 'thumb.php-render' ); $img = Image::newFromName( $fileName ); diff --git a/trackback.php b/trackback.php index 50a3341142..ea3f90fe46 100644 --- a/trackback.php +++ b/trackback.php @@ -4,8 +4,7 @@ * @addtogroup SpecialPage */ require_once( './includes/WebStart.php' ); - -require_once('DatabaseFunctions.php'); +require_once( './includes/DatabaseFunctions.php' ); /** *