php:php
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| php:php [2016/01/25 03:12] – [Config Slow Log for php-fpm] admin | php:php [2025/11/10 13:52] (current) – [Debug error in nginx with php-fpm] admin | ||
|---|---|---|---|
| Line 4: | Line 4: | ||
| * Eclipse pdt: [[php: | * Eclipse pdt: [[php: | ||
| ===== Create PHP simple code and run ===== | ===== Create PHP simple code and run ===== | ||
| - | ==== create | + | ==== Create |
| <code php> | <code php> | ||
| <?php | <?php | ||
| Line 27: | Line 27: | ||
| check http:// | check http:// | ||
| error_log = / | error_log = / | ||
| + | </ | ||
| + | chown www.www / | ||
| </ | </ | ||
| Config turn on/off debug log in **php**: | Config turn on/off debug log in **php**: | ||
| Line 41: | Line 43: | ||
| track_errors = On | track_errors = On | ||
| </ | </ | ||
| + | * 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 48: | 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 63: | 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 127: | Line 157: | ||
| ==== Debug with xdebug ==== | ==== Debug with xdebug ==== | ||
| Refer: [[php: | Refer: [[php: | ||
| - | ==== Query log of mysql server ==== | + | |
| - | [windows] | + | |
| - | log = " | + | |
| - | [linux] | + | |
| - | [mysqld] | + | |
| - | log=/ | + | |
| - | <code bash> | + | |
| - | touch / | + | |
| - | chown mysql.mysql / | + | |
| - | SET GLOBAL general_log = ' | + | |
| - | / | + | |
| - | </ | + | |
| ==== Debug with Javascript ==== | ==== Debug with Javascript ==== | ||
| * Debug with Internet Explorer: Turn on Debug Mode in Internet Options for debugging code javascript error | * Debug with Internet Explorer: Turn on Debug Mode in Internet Options for debugging code javascript error | ||
| * Debug in Chrome: Using Developer Tools for debugging Javascript with break points | * Debug in Chrome: Using Developer Tools for debugging Javascript with break points | ||
| + | ===== PHPUnit ===== | ||
| + | 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 for architecture nginx with php-fpm ==== | + | ==== Config Slow Log in php-fpm ==== |
| < | < | ||
| request_slowlog_timeout = 5s | request_slowlog_timeout = 5s | ||
| Line 339: | Line 371: | ||
| if(!mysql_connect(" | if(!mysql_connect(" | ||
| die(" | die(" | ||
| - | </ | + | </ |
| + | ==== PHP mysql ==== | ||
| + | <code php> | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | </ | ||
| + | ==== PHP mysqli ==== | ||
| + | <code php> | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | </ | ||
| + | ==== Convert from mysql to mysqli ==== | ||
| + | Using tool: https:// | ||
| + | <code bash> | ||
| + | php MySQLConverterTool-master/ | ||
| + | </ | ||
| + | And Modify some missing in tool:< | ||
| + | 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.1453691560.txt.gz · Last modified: (external edit)
