User Tools

Site Tools


php:php

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
php:php [2018/08/28 07:59] โ€“ [Install PHPUnit] adminphp:php [2025/11/10 13:52] (current) โ€“ [Debug error in nginx with php-fpm] admin
Line 45: Line 45:
   * Explain config:display_errors = On => Allow display debug information in front end   * Explain config:display_errors = On => Allow display debug information in front end
 Config turn on debug log in **ngix with php-fpm backend**: Config turn on debug log in **ngix with php-fpm backend**:
-<code>+  * in php-fpm.conf<code>
 [global] [global]
 error_log = /var/log/php-fpm.log error_log = /var/log/php-fpm.log
Line 51: Line 51:
 [www] [www]
 catch_workers_output = yes catch_workers_output = yes
 +</code>
 +  * in php.ini:<code ini>
 +display_errors = On โ‡’ Allow display debug information in front end
 </code> </code>
 Config turn on/off log in httpd: Config turn on/off log in httpd:
Line 66: Line 69:
 ErrorLog "logs/error_log" ErrorLog "logs/error_log"
 LogLevel error LogLevel error
 +</code>
 +==== Debug error in nginx with php-fpm ====
 +You set it per pool, inside: **/etc/php/8.x/fpm/pool.d/www.conf**
 +<code>
 +[www]
 +................
 +catch_workers_output = yes
 +php_admin_flag[log_errors] = on
 +php_admin_value[error_log] = /var/log/php8.2-fpm.log
 +</code>
 +Then restart PHP-FPM
 +
 +Example Before vs After
 +  * Before (catch_workers_output = no):<code>
 +[10-Nov-2025 10:30:21] WARNING: [pool www] child 12345 exited on signal 11 (SIGSEGV)
 +</code>๐Ÿ‘‰ You only see a generic signal crash.
 +  * After (catch_workers_output = yes):<code>
 +[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 /var/www/html/wp-content/themes/flatsome/page.php:12"
 +</code>
 +โœ… 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**:<code ini>
 +log_errors = On
 +error_reporting = E_ALL
 +display_errors = Off
 </code> </code>
 ==== Config in web server to display error log ==== ==== Config in web server to display error log ====
Line 404: Line 431:
 </code>to<code php> </code>to<code php>
 => mysqli_connect("127.0.0.1", "forum_ttb", "xxxxxxxxxx","forum_ttb")); => mysqli_connect("127.0.0.1", "forum_ttb", "xxxxxxxxxx","forum_ttb"));
 +</code>
 +===== PHP curl =====
 +<code php>
 +<?php
 +function curl_post($url, $vars=array(), $second=10)
 +{
 +    try{
 +        $ch = curl_init();
 +        if ($ch === false) {
 +            throw new Exception('failed to initialize');
 +        }
 +        curl_setopt($ch,CURLOPT_TIMEOUT,$second);
 +        curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
 +        curl_setopt($ch,CURLOPT_URL,$url);
 +        curl_setopt($ch,CURLOPT_POST, 1);
 +        curl_setopt($ch,CURLOPT_POSTFIELDS,$vars);
 +        $data = curl_exec($ch);
 +        if ($data === false) {
 +            throw new Exception(curl_error($ch), curl_errno($ch));
 +        }
 +        curl_close($ch);
 +    }catch(Exception $e){
 +        echo "Curl Error: " . $e->getCode . $e->getMessage();
 +    }
 +    if($data)
 +        return $data;
 +    else
 +        return false;
 +}
 </code> </code>
php/php.1535443179.txt.gz ยท Last modified: (external edit)