php:php
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| php:php [2018/08/28 07:27] โ [PHP Slow Log Config] admin | php:php [2025/11/10 13:52] (current) โ [Debug error in nginx with php-fpm] admin | ||
|---|---|---|---|
| Line 45: | Line 45: | ||
| * Explain config: | * Explain config: | ||
| Config turn on debug log in **ngix with php-fpm backend**: | Config turn on debug log in **ngix with php-fpm backend**: | ||
| - | < | + | * in php-fpm.conf< |
| [global] | [global] | ||
| error_log = / | error_log = / | ||
| Line 51: | Line 51: | ||
| [www] | [www] | ||
| catch_workers_output = yes | catch_workers_output = yes | ||
| + | </ | ||
| + | * in php.ini:< | ||
| + | display_errors = On โ Allow display debug information in front end | ||
| </ | </ | ||
| Config turn on/off log in httpd: | Config turn on/off log in httpd: | ||
| Line 66: | Line 69: | ||
| ErrorLog " | ErrorLog " | ||
| LogLevel error | LogLevel error | ||
| + | </ | ||
| + | ==== Debug error in nginx with php-fpm ==== | ||
| + | You set it per pool, inside: **/ | ||
| + | < | ||
| + | [www] | ||
| + | ................ | ||
| + | catch_workers_output = yes | ||
| + | php_admin_flag[log_errors] = on | ||
| + | php_admin_value[error_log] = / | ||
| + | </ | ||
| + | Then restart PHP-FPM | ||
| + | |||
| + | Example Before vs After | ||
| + | * Before (catch_workers_output = no):< | ||
| + | [10-Nov-2025 10:30:21] WARNING: [pool www] child 12345 exited on signal 11 (SIGSEGV) | ||
| + | </ | ||
| + | * After (catch_workers_output = yes):< | ||
| + | [10-Nov-2025 10:30:21] WARNING: [pool www] child 12345 said into stderr: "PHP Fatal error: Uncaught Error: Call to undefined function get_header() in / | ||
| + | </ | ||
| + | โ Now you can see the exact file and line that crashed WordPress. | ||
| + | ๐ ๏ธ Combine With These for Full Debugging, Inside the same pool file or your **php.ini**:< | ||
| + | log_errors = On | ||
| + | error_reporting = E_ALL | ||
| + | display_errors = Off | ||
| </ | </ | ||
| ==== Config in web server to display error log ==== | ==== Config in web server to display error log ==== | ||
| Line 136: | Line 163: | ||
| ===== PHPUnit ===== | ===== PHPUnit ===== | ||
| refer: https:// | refer: https:// | ||
| + | ==== Install PHPUnit ==== | ||
| + | * Install as binary< | ||
| + | wget -O phpunit https:// | ||
| + | chmod +x phpunit | ||
| + | ./phpunit --version | ||
| + | </ | ||
| + | * Install with composer:< | ||
| + | composer require --dev phpunit/ | ||
| + | ./ | ||
| + | </ | ||
| + | ==== Run PHPUnit ==== | ||
| ===== PHP Slow Log Config ===== | ===== PHP Slow Log Config ===== | ||
| ==== Config Slow Log in php-fpm ==== | ==== Config Slow Log in php-fpm ==== | ||
| Line 393: | Line 431: | ||
| </ | </ | ||
| => mysqli_connect(" | => mysqli_connect(" | ||
| + | </ | ||
| + | ===== PHP curl ===== | ||
| + | <code php> | ||
| + | <?php | ||
| + | function curl_post($url, | ||
| + | { | ||
| + | try{ | ||
| + | $ch = curl_init(); | ||
| + | if ($ch === false) { | ||
| + | throw new Exception(' | ||
| + | } | ||
| + | curl_setopt($ch, | ||
| + | curl_setopt($ch, | ||
| + | curl_setopt($ch, | ||
| + | curl_setopt($ch, | ||
| + | curl_setopt($ch, | ||
| + | $data = curl_exec($ch); | ||
| + | if ($data === false) { | ||
| + | throw new Exception(curl_error($ch), | ||
| + | } | ||
| + | curl_close($ch); | ||
| + | }catch(Exception $e){ | ||
| + | echo "Curl Error: " . $e-> | ||
| + | } | ||
| + | if($data) | ||
| + | return $data; | ||
| + | else | ||
| + | return false; | ||
| + | } | ||
| </ | </ | ||
php/php.1535441252.txt.gz ยท Last modified: (external edit)
