有时在一些虚拟主机下(如HostMonster,BlueHost),Zencart网站会莫名奇妙输出空白页面,查看HTTP头,其实可以看到是500错误。
至于500错误的出现原因,一般是由于服务器脚本或是.htaccess有错误。
因为是空白页面没有输出具体的错误位置,所以排查起来很困难。
以下方法是让网站显示了具体的错误位置,错误内容等代码。
application_top.php放入
error_reporting(9);
function onError($errNo, $errMsg, $file, $line, $errcontext) {
$report_title ='错误报告';
$report_msg = "
<strong>错误类型:</strong><blockquote>$errType($errNo)</blockquote>
<strong>错误位置:</strong><blockquote>$file 第 $line 行</blockquote>
<strong>错误信息:</strong><blockquote>$errMsg</blockquote>";
//print_r($errcontext);
echo $report_msg;
echo '<hr>';
}
set_error_handler('onError');
将以上代码添加在
application_top.php 文件的适当位置。
再次打开网站会发xian具体的输出文件位置已经取出。
-------------------------------------------------------------------------------------------
调试PHP错误经常用到的一些
时间:12-05-24 栏目:问题及解决 作者:admin 评论:3 点击: 3,195 次
1
2
3
4
|
ini_set ( 'error_log' , 'errorLog.txt' );#记录下来所有发现的错误到文件里去。
ini_set ( 'display_errors' , 1);#嗯,要显示错误
ini_set ( 'memory_limit' , '512M' );#有些错误的出现和内存使用有关系,把这个值调大试试看
|
ini_set("error_reporting",E_ALL);
ini_set("error_log","<日志文件名>")
ini_set("log_errors",1);
#所有 ini_set的内容都可以在php.ini中定义
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
function _e( $msg , $type = '' ){ static $i =0; $i ++; $error [ 'msg' ] = $msg ; $error [ 'type' ] = $type ; $GLOBALS [ERROR_STACK_NAME][ $i ] = $error ; return ERROR_STACK_NAME. $i ; } /** * 错误处理 */ function onError( $errNo , $errMsg , $file , $line , $errcontext ) { $errorlevels = array ( 2048 => 'Warning' , 2048 => 'Notice' , 1024 => 'Warning' , 1024 => 'Notice' , 512 => 'Warning' , 256 => 'Error' , 128 => 'Warning' , 64 => 'Error' , 32 => 'Warning' , 16 => 'Error' , 8 => 'Notice' , 4 => 'Error' , 2 => 'Warning' , 1 => 'Error' ); //print_r(array('code'=>$errno, 'string'=>$errstr, 'file'=>$errfile, 'line'=>$errline,'codeinfo'=>$errorlevels[$errno])); $t = error_reporting (); if (!( $errNo & error_reporting ())) { return ; } $errType = $errNo ; /** Get Advance Error msg **/ if ( strpos ( $errMsg ,ERROR_STACK_NAME)==0){ $i = substr ( $errMsg , strlen (ERROR_STACK_NAME)); if (isset( $GLOBALS [ERROR_STACK_NAME][ $i ])){ $error = $GLOBALS [ERROR_STACK_NAME][ $i ]; $errMsg = $error [ 'msg' ]; $errType = $error [ 'type' ]; } } $errMsg = nl2br ( $errMsg ); if ( $errType == 'smarty' ){ $errType = '模版系统错误' ; } elseif ( $errType == 'sql' ){ $errType = '数据库操作错误' ; } else { $errType = "PHP错误[$errType]" ; } $title = '系统错误' ; $msg = " <strong>错误类型:</strong><blockquote> $errType </blockquote> <strong>错误位置:</strong><blockquote> $file 第 $line 行</blockquote> <strong>错误信息:</strong><blockquote> $errMsg </blockquote> "; echo $msg ; flush (); //msgBox($title,$msg,'',false,2); exit (); } function shutdown_function(){ $errorlevels = array ( 2048 => 'Warning' , 2048 => 'Notice' , 1024 => 'Warning' , 1024 => 'Notice' , 512 => 'Warning' , 256 => 'Error' , 128 => 'Warning' , 64 => 'Error' , 32 => 'Warning' , 16 => 'Error' , 8 => 'Notice' , 4 => 'Error' , 2 => 'Warning' , 1 => 'Error' ); $error = error_get_last(); if ( $error ){ echo '</tr></table></div></div></div></iframe><div style="clear:both"></div><div style=" background-color:#FFBB00"><pre>' ; echo '最后一个错误:' ; $error [ 'type' ]= $errorlevels [ $error [ 'type' ]]; print_r( $error ); debug_print_backtrace(); echo '</pre></div>' ; } else { echo '本页面无错误!' ; } } register_shutdown_function( 'shutdown_function' );#定义最后一个错误捕获 define( 'ERROR_STACK_NAME' , 'ERROR_STACK' ); set_error_handler( 'onError' );#定义错误处理函数 error_reporting (9); |
LH的方法是:
2.从链接入手,通过访问不同模块确定错误可能存在与某个模块
3.从代码入手,链接反复出错,需要查看框架其实处开始
4.从服务器配置入手,切换服务器配置
声明: 本文由(admin)原创编译,转载请保留链接: 调试PHP错误经常用到的一些