; php.ini
error_reporting = E_ALL | E_STRICT
display_errors = On
log_errors = On
error_log = /var/log/php/error.log
即使是 Notice(如未定義變數)也要修正,往往隱藏邏輯 Bug。
display_errors = Off
log_errors = On
error_log = /var/log/php/error.log
@@$fp = fopen(...) 會吞沒所有錯誤,導致除極度困難。僅在明確預期失敗且已有後續處理時使用(如 @mkdir() 忽略已存在錯誤)。
$fp = @fsockopen("example.com", 80, $errno, $errstr, 30);
if (!$fp) {
error_log("連線失敗 [$errno]: $errstr");
// 可根據 errno 判斷:111=連線被拒、110=逾時等
}
適用函數:fsockopen、stream_socket_client、mysql_connect (舊)、mysqli_connect_errno() 等。
zend_extension=xdebug.so
xdebug.mode=debug,develop,trace,profile
xdebug.start_with_request=yes
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
xdebug.log=/var/log/xdebug.log
var_dump() 自動著色、摺疊、限制深度。xdebug.mode=profile 輸出 CacheGrind 格式,用 QCacheGrind/WebGrind 視覺化熱點。error_log(print_r($var, true)) 或 Xdebug 監看memory_get_peak_usage()、microtime(true) 手動埋點slow_query_log)