Manual:How to debug/zh
這頁提供基本除錯Mediawiki的介紹。首要的是你需要知道他是"echo" generally does不能運作; this is part of the general design.
Contents |
PHP錯誤 [edit]
檢察PHP錯誤,你要LocalSettings.php上加上以下內容:
error_reporting(E_ALL); ini_set("display_errors", 1);
加入後,PHP錯誤會顯示on-page。This might make it easier for attackers to find a way into your server, so disable it again when you have found the problem.
Note that fatal PHP errors may happen before the lines above are ever executed, or may prevent them from being shown. Fatal PHP errors are usually logged to Apache's error log — check the error_log setting in php.ini (or use phpinfo()).
You can enable more details (like a stack trace) to be shown for some types of errors:
$wgShowExceptionDetails = true;
this is especially useful when debugging errors in the PHP code (as opposed to configration problems).
SQL錯誤 [edit]
To display SQL errors in錯誤訊息instead of "(SQL query hidden)", add the following to LocalSettings.php:
$wgShowSQLErrors = true; $wgDebugDumpSql = true;
In-depth debugging [edit]
Logging [edit]
For much greater detail, you need to profile and log errors.
To save SQL errors to a log, add $wgDebugLogFile to the LocalSettings.php file. Change the value to a text file where you want to save the debug trace output.
/** * The debug log file should be not be publicly accessible if it is used, as it * may contain private data. But it must be in a directory to which PHP run * within your Web server can write. */ $wgDebugLogFile = 'c:/Program Files/Apache Group/htdocs/mediawiki/debug_log.txt';
This file will contain all of the built-in MediaWiki debug information as well as anything you try to log. To create a custom log file that only holds your debug statements, add this to LocalSettings.php.
/** * The debug log file should be not be publicly accessible if it is used, as it * may contain private data. But it must be in a directory to which PHP run * within your Web server can write. */ $wgDebugLogGroups = array( 'myextension' => 'logs/myextension.log', 'anotherloggroup' => 'logs/another.log', );
Then debug to this custom log using a statement like this:
// ...somewhere in your code if($bad) { wfDebugLog('myextension', 'Something is not right: ' . print_r($editpage->mArticle, true) ); }
Profiling [edit]
詳情,你需要允許profiling. Profiling tracks code execution during a page action and reports back the percentage of total code execution that was spent in any specific function. The generated profile only includes functions that have specifically been marked to be profiled.
| MediaWiki version: | ≥ 1.8 |
To enable profiling, you need to modify the StartProfiler.php. By default the file includes a ProfilerStub which just dumps profiling information. To instead direct this information to a file, edit StartProfiler.php so that it looks like this:
#require_once( dirname(__FILE__).'/includes/ProfilerStub.php' ); require_once( dirname(__FILE__).'/includes/Profiler.php' ); $wgProfiler = new Profiler;
Then you can customize profiling options in LocalSettings.php (not StartProfiler.php):
Common configuration: (both <1.7 and >1.8)
/** Only record profiling info for pages that took longer than this */ $wgProfileLimit = 0.0; /** Don't put non-profiling info into log file */ $wgProfileOnly = false; /** Log sums from profiling into "profiling" table in db. */ $wgProfileToDatabase = false; /** If true, print a raw call tree instead of per-function report */ $wgProfileCallTree = false; /** Should application server host be put into profiling table */ $wgProfilePerHost = false; /** Settings for UDP profiler */ $wgUDPProfilerHost = '127.0.0.1'; $wgUDPProfilerPort = '3811'; /** Detects non-matching wfProfileIn/wfProfileOut calls */ $wgDebugProfiling = false; /** Output debug message on every wfProfileIn/wfProfileOut */ $wgDebugFunctionEntry = 0; /** Lots of debugging output from SquidUpdate.php */ $wgDebugSquid = false;
| MediaWiki version: | ≤ 1.7 |
In MediaWiki 1.7 and earlier, instead of editing StartProfiler.php, you have to set $wgProfiling to true. This will generate basic page timing information in the file defined by $wgDebugLogFile.
In addition to the settings list above, these additional settings are available:
/** Enable for more detailed by-function times in debug log */ $wgProfiling = true; /** Only profile every n requests when profiling is turned on */ $wgProfileSampleRate = 1; /** If not empty, specifies profiler type to load */ $wgProfilerType = '';
Advanced profiling [edit]
Once you have enabled profiling, you can trace code execution through any function that you want to investigate as a bottleneck by wrapping the function with the following code:
function doSomething() { wfProfileIn( __METHOD__ ); # You can replace __METHOD__ with any string. This will appear in the profile. # The actual function wfProfileOut( __METHOD__ ); }
After you've added this information, browse to a page in the wiki. This will generate profiling info in the log file you defined above. Change $wgProfileCallTree in LocalSettings.php to true or false for different display formats.
Logging to Database [edit]
To log profiling information to a database, first you'll have to create a profiling table in your MediaWiki database the table definition in the file maintenance/archives/patch-profiling.sql. Then set $wgProfileToDatabase = true; in LocalSettings.php.
Note: $wgProfileCallTree must be set to false.
Viewing Profile Info [edit]
If you log your profiling information to the databse, you can view the information in a webpage by browsing to profileinfo.php. You must also set $wgEnableProfileInfo = true; in AdminSettings.php. Then, after gathering data by browsing wiki pages, visit profileinfo.php to see how much time your profiled code is using and how many times it's being called.
See also [edit]
| Language: | English • 日本語 • 中文 |
|---|