apache - Determining the run-time source of the PHP.INI values that were used to evaluate the pre-processing? -
is there way determine, via enhanced error log message or output variable, value of core php directives' values used @ run-time? identical phpinfo() output each error.
a basic example error_reporting variable. if /etc/php.ini value set @ x, , phpinfo() states that php.ini file in-fact intended source of ini variables. if user implements run-time adjustment variable in code, able output error_reporting variable @ time when error thrown.
such when php.ini file has e_all & ~e_strict e_strict errors being reported in log files, great have way enhance output logfile shows "stacktrace" of system variables active, or @ least modified, , source each error reported, perhaps via error-id added httpd log corresponds optional file shows run-time settings @ time of error.
i realize try/catch used this, don't believe implemented in practicality large deployment of mixed 3rd party code.
does such mechanism exist in php, or has developed 1 (google says not likely)? vary valuable many other cases of errors, helping expedite merging of code-bases through relativity of variable settings error message.
i hope i'm looking @ wrong , there easy fix i'm missing.
thanks!
i have working example "pecl runkit" had trouble installing apd
on fresh distrib (it's old library).
you can install runkit
pecl:
pecl install runkit
and add following lines in php.ini:
extension=runkit.so runkit.internal_override=1
i forgot mention error_reporting
can defined in different way using error_reporting()
function or ini_set
. have care each function. first copy old ini_set
using runkit_function_copy
, redefine using runkit_function_redefine
i use debug_bactrace(1)
calling file , line number.
and catch both non-fatal , fatal error, have use set_error_handler
, register_shutdown_function
.
the following code output, after error, ini_set
called , filename/line.
error (type=2): division 0 in file /var/www/html/test.php line 47
ini set stack
- error_reporting defined here (in order):
- /var/www/html/test.php, line 16, value: 0
- /var/www/html/test.php, line 17, value: 2
- /var/www/html/test.php, line 18, value: 1
- /var/www/html/test.php, line 19, value: 32767
code:
<?php runkit_function_copy("ini_set", "old_ini_set"); runkit_function_redefine("ini_set", '$key,$value', ' global $iniset; $trace=debug_backtrace(1); $iniset[$key][]=$trace[0]; old_ini_set($key, $value);'); runkit_function_redefine("error_reporting", '$value', ' global $iniset; $trace=debug_backtrace(1); $iniset["error_reporting"][]=$trace[0]; old_ini_set($key, $value);'); // let test ini_set("error_reporting", 0); ini_set("error_reporting", e_warning); error_reporting(e_error); ini_set("error_reporting", e_all); set_error_handler("custom_error_handler"); register_shutdown_function("custom_error_handler"); function custom_error_handler($errno=null, $errstr=null) { global $iniset; if (!($error=func_get_args())) { $error=error_get_last(); if ($error!=e_error) $error=null; } if ($error) { echo "error (type=$error[0]): $error[1]\n in file $error[2] line $error[3]<br />\n"; echo "ini set stack<br />\n"; echo "<ul>"; foreach ($iniset $key=>$val) { echo "<li>$key defined here (in order):<ul>"; foreach ($val $def) { echo "<li>{$def['file']}, line {$def['line']}, value: ".array_pop($def['args'])."</li>"; } echo "</li></ul>"; } echo "</table>"; } } // division 0 12/0;
previous post:
you can value of local , global configuration options ini_get_all()
function.
to retrieve values of both local , global value, can set $details
parameter true:
ini_get_all(null, true);
you can value individual options ini_get()
(for runtime value) , get_cfg_var()
(for global php.ini value) functions.
$global_value=get_cfg_var("error_reporting"); $local_value=ini_get("error_reporting"); echo "error reporting (local value: $local_value, global value: $global_value)\n"
in order see results when error occurs, have catch errors.
for non fatal errors, can use set_error_handler()
for fatal errors, have define shutdown_function(), see how catch php fatal error
Comments
Post a Comment