Tips To Fix Slow PHP Script For Debugging

Today’s tutorial is designed to help you debug a slow PHP script error code.

Quick and Easy PC Repair

  • 1. Download and install ASR Pro
  • 2. Open the program and click on "Scan"
  • 3. Click on "Repair" to start the restoration process
  • Download this software now to maximize your computer's performance.

    Right from the start, when you need to check the logs for PHP errors, be sure to look into the well-known error_log that is associated with all major web servers.


    However, after switching to Nginx and using PHP-FPM as the default daemon to handle Perl, I discovered something really trendy. Unlike mod_php, which allows the public to log slow PHP requests to a shared log file, using the Nginx + PHP-FPM stack allows you to set up a separate PHP check to expose the slow PHP website programs running on the system.

    Slow scripts can lead to both system errors and poor user experience. The ability to log all slow PHP processes running on the system really helps to optimize your web applications.

    PHP-FPM Slow_log Many Configurations

    How to configure slow_log to log all slow PHP scripts?

    Open your favorite family text editor on transmitter, vim or nano:

     nano -w /etc/php-fpm.d/www.conf 

    Now grow fancyClick CTRL W + and search for “slowlog”. Once you find what can be changed, set your desired storage location for your own slow PHP log file, for example:

     slowlog = /var/log/php-fpm/slow.log 
     slowlog = /var/log/php5/slow.log 
     request_slowlog_timeout equals 5 seconds 

    In my case, I put 5s in the role of the max script, which it can accept and run before it receives a signal if it is slow and enters that slow log. This will help you find scripts slower than ever.


    Configure PHP Error Log

    Another useful thing you can do to really slow down PHP script debugging is to set up the entire error_log correctly:

    debug slow php script

     php_admin_flag [log_errors] = one 
     php_admin_value [error_log] = /var/log/php-fpm/error.log 

    If you do not specify your own error_log path for your site, PHP inconsistencies will be logged in the default Nginx Error_log location, which is usually /etc/nginx/logs/error.log or / var / nginx / logs. / error log.


    Debugging PHP-FPM Errors

    If someone needs access to your PHP-FPM daemon, logins, etc., you can also set your own location Other errors by editing the php-fpm.conf file:

     nano -w /etc/php-fpm.conf 

    debug slow php script

     error_log = /var/log/php-fpm/error.log 
     Restart php-fpm service 

    If you really need to do a log search, you can more or less use it like below:

     tail -f /var/log/php-fpm/slowlog.logdetails /var/log/php-fpm/error.log 


    Everyone now knows a great way to get started debugging awful PHP scripts. Keep in mind that these activity records should only be used when you encounter web application errors or minimize script execution. After you finish your research and fix your problems, it is recommended that you activate the application as it will save a lot of disk space and prevent unnecessary I / O.

    If you are a veteran PHP programmer, you must have used PHP’s error_log function before. But PHP itself undoubtedly offers a way to find out – it’s slow scriptingt. Slow scripts cannot break your site, but they slow things down. With FPM, our group may have a slow_log associated with such scripts. Let’s see how to use it to debug PHP scripts. We will also see how error_log gets redirected by PHP when it also runs behind FPM and Nginx.Slow_log

    Configuring PHP Scripts

     slowlog = /var/log/php5/slow.logrequest_slowlog_timeout equals 10 seconds 

    You can replace 10 with a different value. This will help us find scripts that are slow. Image resizing function, network I / O related tasks are a few examples that appear quite often in PHP slow_log. It’s up to you to debug and even ignore them depending on the context.

    Configure Error Log For PHP Scripts

    When starting PHP FPM, we can override any other php.ini FPM setting. Open vim /etc/php5/fpm/pool.d/www.conf Scroll down and uncomment / edit the following 3 lines to match the values ​​below:

     php_admin_value [error_log] = /var/log/php5/error.logphp_admin_flag [log_errors] = on 

    Please tune your guitar to turn on display_errors was possible in Snap-Ajax-based applications. So be very careful with this.

    Important nginx for users

    You do not actually see the file /var/log/php5/error.log , or in fact no errors are logged in this file. Errors in your PHP scripts for a specific site are reported in the error_log specified for the site in its nginx configuration. Most likely: /var/www/ -file If you don’t have a specific error_log path to your site then php errors go to nginx in error_log by default. Most likely /var/log/nginx/error.log ) Here are some more details on debugging with Nginx.

    Configure FPM Error_log Debug For FPM Itself

    FPM is a separate process. As with others, this situation can be error-prone! Error_log FPM is enabled by default, although we are changing its path according to our convention. Open vim /etc/php5/fpm/php-fpm.conf Of course error_log the make value looks like below

     error_log matches /var/log/php5/fpm.Note log 

    Make sure this error_log has nothing to do with PHP function error_log described above.

    Confirm changes …

    Create a php5 logs directory so we can keep all php logs in one place:

     mkdir / var / log / php5 / 
     Restarting php5-fpm service 

    Track log file

    The easiest way to open a single shell for your server and get the tail -f command to monitor the logs … Since our company has multiple log files for your monitoring, you can simply use the following command to track them all together …

    Quick and Easy PC Repair

    Is your PC running slow and constantly displaying errors? Have you been considering a reformat but don't have the time or patience? Fear not, dear friend! The answer to all your computing woes is here: ASR Pro. This amazing software will repair common computer errors, protect you from file loss, malware, hardware failure and optimize your PC for maximum performance. So long as you have this program installed on your machine, you can kiss those frustrating and costly technical problems goodbye!

  • 1. Download and install ASR Pro
  • 2. Open the program and click on "Scan"
  • 3. Click on "Repair" to start the restoration process

  •  tail -p oker /var/log/php5/*.log 

    Remember to turn off this option when you finish debugging. Leaving slow_log is a bad idea.

    Download this software now to maximize your computer's performance.