php:php
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| php:php [2015/08/04 07:57] – [config debug mode in PHP] 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 10: | Line 10: | ||
| ?> | ?> | ||
| </ | </ | ||
| - | ==== create | + | ==== Create |
| <code php> | <code php> | ||
| <?php | <?php | ||
| Line 16: | Line 16: | ||
| ?> | ?> | ||
| </ | </ | ||
| - | ==== run PHP code ==== | + | ==== Run PHP code ==== |
| * linux: <code bash> | * linux: <code bash> | ||
| php helloworld.php | php helloworld.php | ||
| Line 24: | Line 24: | ||
| </ | </ | ||
| ===== How to debug in PHP and Javascript ===== | ===== How to debug in PHP and Javascript ===== | ||
| - | ==== config | + | ==== Config |
| 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 | ||
| </ | </ | ||
| - | Config turn on debug log in **php-fpm**: | + | * Explain config: |
| - | < | + | Config turn on debug log in **ngix with php-fpm |
| + | * 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 64: | Line 70: | ||
| LogLevel error | LogLevel error | ||
| </ | </ | ||
| - | ==== config | + | ==== 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 nginx< | * in nginx< | ||
| ###demo.vn | ###demo.vn | ||
| Line 107: | Line 137: | ||
| </ | </ | ||
| </ | </ | ||
| - | ==== debug with php code ==== | + | ==== Debug with php code ==== |
| * Debug with print< | * Debug with print< | ||
| print(variable_name) | print(variable_name) | ||
| Line 125: | Line 155: | ||
| ?> | ?> | ||
| </ | </ | ||
| - | ==== 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 ===== | ||
| + | ==== Config Slow Log in php-fpm ==== | ||
| + | < | ||
| + | request_slowlog_timeout = 5s | ||
| + | slowlog = / | ||
| + | </ | ||
| + | ==== Config Slow Log for php ==== | ||
| ===== Basic Syntaxs ===== | ===== Basic Syntaxs ===== | ||
| ==== PHP tags ==== | ==== PHP tags ==== | ||
| Line 332: | 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.1438675061.txt.gz · Last modified: (external edit)
