PHP瑙e喅闂杩涘寲璁(鏁寸悊绗旇)
鏌ョ湅PHP閿欒淇℃伅
1銆佷慨鏀筽hp.ini閰嶇疆

php.ini涓璬isplay_errors / display_startup_errors 璁剧疆涓篛n  
php.ini涓璭rror_reporting 璁剧疆涓篍_ALL  
PHP浠g爜涓缃甧rror_reporting(E_ALL) 
2銆丳HP涓墦寮鎶ラ敊

error_reporting(E_ALL);
ini_set ('display_errors', 'On');
鏈変簺鎯呭喌涓媝hp.ini閰嶇疆涓叧闂簡閿欒鏄剧ず锛岄渶瑕佷慨鏀筽hp.ini鎵撳紑閿欒淇℃伅锛屾垨鑰呴敊璇俊鎭瀵煎嚭鍒颁簡鏃ュ織鏂囦欢锛岃繖绉嶆儏鍐靛彲浠ョ洿鎺ailf php_error.log鏉ョ湅閿欒淇℃伅銆

澶氫釜鐗堟湰鐨刾hp鎴杙hp-cli涓巔hp-fpm鍔犺浇涓嶅悓鐨勯厤缃
which php 
#寰楀埌鍙嶉 /usr/bin/php,鏌ョ湅PHP瀹夎鍦ㄥ摢
php -i |grep php.ini
#寰楀埌鍔犺浇閭d釜php.ini,濡備笅
Configuration File (php.ini) Path => /usr/local/etc/php/5.6
Loaded Configuration File => /usr/local/etc/php/5.6/php.ini
鎵撳嵃鍗曟璋冭瘯
1銆丳HP鐨刧etTrace
fiel:鍙戠敓寮傚父鐨凱HP绋嬪簭鏂囦欢鍚嶇О锛
line:鍙戠敓寮傚父鐨勪唬鐮佹墍鍦ㄧ殑琛屽彿锛
function锛氬彂鐢熷紓甯哥殑鍑芥暟鎴栨柟娉曪紱
class:鍙戠敓寮傚父鐨勫嚱鏁版垨鏂规硶鎵鍦ㄧ殑绫伙紱
type:璋冪敤鍙戠敓寮傚父鐨勫嚱鏁版垨鏂规硶鐨勭被鍨嬶紙鈥::鈥濊皟鐢ㄩ潤鎬佺被鎴愬憳锛屸->鈥濊皟鐢ㄥ疄渚嬪寲瀵硅薄锛夛紱
args:鍙戠敓寮傚父鐨勫嚱鏁版垨鏂规硶鎵鎺ュ彈鐨勫弬鏁般

<?php
$path = "www.phpdo.net";
try
{
    file_open($path);
}
catch(Exception $e)
{
    echo "寮傚父淇℃伅".$e->getMessage()."\n";
    echo "寮傚父浠g爜".$e->getCode()."\n";
    echo "寮傚父鏂囦欢".$e->getFile()."\n";
    echo "寮傚父浠g爜鎵鍦ㄨ".$e->getLine()."\n";
    echo "浼犻掕矾绾匡細";
    print_r($e->getTrace()); //浠ユ暟缁勭殑褰㈠紡杩斿洖璺熻釜寮傚父鐨勬瘡涓閮ㄧ殑浼犻掕矾绾
    echo $e->getTraceAsString();//杩斿洖鏍煎紡鍖栨垚瀛楃涓茬殑getTrace鍑芥暟淇℃伅
}

function file_open($path)
{
    if(!file_exists($path))
    {
        throw new exception("www.phpdo.net杩欎釜鏂囦欢涓嶅瓨鍦",1);
    }
    if(!fopen($path,"r"))
    {
        throw new exception("www.phpdo.net杩欎釜鏂囦欢鏃犳硶鎵撳紑",2);
    }
}
?>
缁撴灉锛

寮傚父淇℃伅www.phpdo.net 杩欎釜鏂囦欢涓嶅瓨鍦 寮傚父浠g爜1 寮傚父鏂囦欢E:\xampp\htdocs\php\Test\10.2.6.php 寮傚父浠g爜鎵鍦ㄨ22

浼犻掕矾绾匡細

Array ( [0] => Array ( [file] => E:\xampp\htdocs\php\Test\10.2.6.php [line] => 5 [function] => file_open [args] => Array ( [0] => www.phpdo.net ) ) )

#0 E:\xampp\htdocs\php\Test\10.2.6.php(5): file_open(鈥榳ww.phpdo.net鈥) #1 {main}
2銆丳HP debug_backtrace()
鍚嶇О 绫诲瀷 鎻忚堪
function 瀛楃涓 褰撳墠鐨勫嚱鏁板悕銆
line 鏁存暟 褰撳墠鐨勮鍙枫
file 瀛楃涓 褰撳墠鐨勬枃浠跺悕銆
class 瀛楃涓 褰撳墠鐨勭被鍚
object 瀵硅薄 褰撳墠瀵硅薄銆
type 瀛楃涓 褰撳墠鐨勮皟鐢ㄧ被鍨嬶紝鍙兘鐨勮皟鐢細
杩斿洖: "->"  - 鏂规硶璋冪敤
杩斿洖: "::"  - 闈欐佹柟娉曡皟鐢
杩斿洖 nothing - 鍑芥暟璋冪敤
args 鏁扮粍 濡傛灉鍦ㄥ嚱鏁颁腑锛屽垪鍑哄嚱鏁板弬鏁般傚鏋滃湪琚紩鐢ㄧ殑鏂囦欢涓紝鍒楀嚭琚紩鐢ㄧ殑鏂囦欢鍚嶃
<?php
function one($str1, $str2)
 {
 two("Glenn", "Quagmire");
 }
function two($str1, $str2)
 {
 three("Cleveland", "Brown");
 }
function three($str1, $str2)
 {
 print_r(debug_backtrace());
 }

one("Peter", "Griffin");
?>
3銆佸叾浠(var_dump,die(),exit()绛)
PHP杩涚▼璺熻釜鏌ョ湅
浠涔堟槸strace?
strace鏄竴涓潪甯哥畝鍗曠殑宸ュ叿锛屽畠鍙互璺熻釜绯荤粺璋冪敤鐨勬墽琛屻傛渶绠鍗曠殑鏂瑰紡锛屽畠鍙互浠庡ご鍒板熬璺熻釜binary鐨勬墽琛岋紝鐒跺悗浠ヤ竴琛屾枃鏈緭鍑虹郴缁熻皟鐢ㄧ殑鍚嶅瓧锛屽弬鏁板拰杩斿洖鍊笺
鍏跺疄瀹冨彲浠ュ仛鐨勬洿澶氾細
鍙互瀵圭壒瀹氱殑绯荤粺璋冪敤鎴栬呭嚑缁勭郴缁熻皟鐢ㄨ繘琛岃繃婊
鍙互閫氳繃缁熻鐗瑰畾绯荤粺璋冪敤鐨勮皟鐢ㄦ鏁般佽楄垂鐨勬椂闂淬佹垚鍔熷拰澶辫触鐨勬鏁版潵閰嶇疆(profile)绯荤粺璋冪敤鐨勪娇鐢↖
璺熻釜鍙戦佺粰杩涚▼鐨勪俊鍙烽噺
鍙互閫氳繃pid闄勭潃(attach)鍒颁换浣曡繍琛岀殑杩涚▼
濡傛灉浣犱娇鐢ㄧ殑鏄叾瀹僓nix绯荤粺锛屽畠绫讳技浜"truss"銆傚叾瀹冩洿澶嶆潅鐨勬槸Sun鐨凞trace.

璋冪敤:

strace [ -dffhiqrtttTvxx ] [ -acolumn ] [ -eexpr ] 鈥   
[ -ofile ] [ -ppid ] 鈥 [ -sstrsize ] [ -uusername ] [ command [ arg 鈥 ] ]  
  
strace -c [ -eexpr ] 鈥 [ -Ooverhead ] [ -Ssortby ] [ command [ arg 鈥 ] ]   
鍔熻兘: 
璺熻釜绋嬪紡鎵ц鏃剁殑绯荤粺璋冪敤鍜屾墍鎺ユ敹鐨勪俊鍙.閫氬父鐨勭敤娉曟槸strace鎵ц涓鐩村埌commande缁撴潫.

浣跨敤strace php test.php锛屾垨鑰卻trace -p 杩涚▼ID銆俿trace灏卞彲浠ュ府鍔╀綘閫忚繃鐜拌薄鐪嬫湰璐紝鎺屾彙绋嬪簭鎵ц鐨勮繃绋嬨

濡傦細
strace -p PID鍒嗘瀽php-fpm杩涚▼

at("/data/tdocs/webroot/go/./Widget/boutique.inc.php", 0x7fffc74cb320) = -1 ENOENT (No such file or directory)
lstat("/data/tdocs/webroot/go/./Widget/openapi.inc.php", 0x7fffc74cb320) = -1 ENOENT (No such file or directory)
lstat("/data/tdocs/webroot/go/./Widget/groupnew.inc.php", 0x7fffc74cb320) = -1 ENOENT (No such file or directory)
lstat("/data/tdocs/webroot/go/./Widget/groupStatistical.inc.php", 0x7fffc74cb320) = -1 ENOENT (No such file or directory)
lstat("/usr/share/pear/Widget/groupStatistical.inc.php", 0x7fffc74cb320) = -1 ENOENT (No such file or directory)
lstat("/usr/share/php/Widget/groupStatistical.inc.php", 0x7fffc74cb320) = -1 ENOENT (No such file or directory)
鎬庝箞浣跨敤瀹冿紵
鎵惧嚭绋嬪簭鍦╯tartup鐨勬椂鍊欒鍙栫殑鍝釜config鏂囦欢锛

$ strace php 2>&1 | grep php.ini  
open("/usr/local/bin/php.ini", O_RDONLY) = -1 ENOENT (No such file or directory)  
open("/usr/local/lib/php.ini", O_RDONLY) = 4  
lstat64("/usr/local/lib/php.ini", {st_mode=S_IFLNK|0777, st_size=27, ...}) = 0  
readlink("/usr/local/lib/php.ini", "/usr/local/Zend/etc/php.ini", 4096) = 27  
lstat64("/usr/local/Zend/etc/php.ini", {st_mode=S_IFREG|0664, st_size=40971, ...}) = 0  
strace -e open php 2>&1 | grep php.ini  
open("/usr/local/bin/php.ini", O_RDONLY) = -1 ENOENT (No such file or directory)  
open("/usr/local/lib/php.ini", O_RDONLY) = 4  
鏌愪釜杩涚▼鐜板湪鍦ㄥ仛浠涔?

strace -p 15427  
Process 15427 attached - interrupt to quit  
futex(0x402f4900, FUTEX_WAIT, 2, NULL   
Process 15427 detached  
鏄皝鍋疯蛋浜嗘椂闂达紵

浣犲彲浠ラ噸鏂扮紪璇慳pp锛屾墦寮profiling锛屼互鑾峰彇绮剧‘鐨勪俊鎭備絾鏄氬父鍒╃敤strace闄勭潃(attach锛変竴涓繘绋嬩互蹇熷湴鐪嬩竴涓嬪綋鍓嶆椂闂磋姳璐瑰湪鍝噷闈炲父鏈夌敤銆傚彲浠ョ湅涓嬫槸鍚90%鐨凜PU鐢ㄥ湪鐪熸鐨勫伐浣滐紝鎴栬呯敤鍦ㄥ叾瀹冩柟闈簡銆

strace -c -p 11084  
Process 11084 attached - interrupt to quit  
Process 11084 detached  
% time     seconds  usecs/call     calls    errors syscall  
------ ----------- ----------- --------- --------- ----------------  
 94.59    0.001014          48        21           select  
  2.89    0.000031           1        21           getppid  
  2.52    0.000027           1        21           time  
------ ----------- ----------- --------- --------- ----------------  
100.00    0.001072                    63           total  
閫氫俊杩囩▼濡備綍鍒嗘瀽-tcpdump锛
鐢ㄧ畝鍗曠殑璇濇潵瀹氫箟tcpdump锛屽氨鏄細dump the traffic on a network锛屾牴鎹娇鐢ㄨ呯殑瀹氫箟瀵圭綉缁滀笂鐨勬暟鎹寘杩涜鎴幏鐨勫寘鍒嗘瀽宸ュ叿銆 tcpdump鍙互灏嗙綉缁滀腑浼犻佺殑鏁版嵁鍖呯殑鈥滃ご鈥濆畬鍏ㄦ埅鑾蜂笅鏉ユ彁渚涘垎鏋愩傚畠鏀寔閽堝缃戠粶灞傘佸崗璁佷富鏈恒佺綉缁滄垨绔彛鐨勮繃婊わ紝骞舵彁渚沘nd銆乷r銆乶ot绛夐昏緫璇彞鏉ュ府鍔╀綘鍘绘帀鏃犵敤鐨勪俊鎭

浠ヤ笂灏辨槸PHP瑙e喅闂杩涘寲璁(鏁寸悊绗旇)鐨勮缁嗗唴瀹癸紝鏇村淇℃伅璇峰叧娉∣D浜戝叾瀹冪浉鍏虫枃绔狅紒



鏈枃URL锛http://www.odweb.cn/news_show.html?id=139