FeaturesWP CloudPricingEE CLIContactMy Account
Features
Team Access & User Permissions
Install
Resources
Community
CLEAR
Tutorials
PHP
Debugging PHP Scripts Using slow_log and more
Topics
On this page
-
- Getting Started
- Git and File-System Layout (non-default setup)
- Version Constraints
- Managing Themes and Plugins (for entire WordPress site)
- Updating Themes and Plugins (for entire WordPress site)
- Adding Composer Support to Your Own Themes and Plugins (for developers)
- Using Composer to Manage Own Theme/Plugin Dependencies (for developers)
-
- Assigning Multiple IP Addresses to Single LAN Card
- Disable IPv6 on Ubuntu 12.04
- dsh – distributed shell
- fdupes – find & replace duplicate files with hardlinks
- GPG Keys Cheatsheet
- Increase "Open Files Limit"
- kill all php, nginx, mysql or any kind of processes
- Passwordless Authentication for SSH
- Screen
- search replace in multiple files useing grep xargs sed
- Setup sftp
- sysctl.conf
- Timezone Sync
- Using Google Public DNS on Ubuntu Server
- Using openssl to match private key, cerificate and CSR
- Configure Postfix to Use Gmail SMTP on Ubuntu
- Logrotate Example for Custom Logs
- PHP 5.5, MySQL, Postfix, Nginx and WordPress on Ubuntu
- Serverdensity
- Upgrade Ubuntu 10.04 to 12.04
- Using find and sed to replace strings in multiple files
- Webmin
-
- .my.cnf – mysql user & password
- Analyse slow-query-log using Anemometer
- Improving MySQL Query Cache
- MySQL Query Profiling
- Reset MySQL root password
- tuning-primer.sh – an alternative for mysqltuner
- Using MariaDB 10
- Install/Upgrade to MySQL 5.6 on Ubuntu 12.04 LTS
- Change WordPress Domain Name
- Character Sets and Collations
- Enable innodb_file_per_table
- Enable Remote Access (Grant)
- Installing Percona Toolkit
- Using tmpfs for temporary folder creation
- YARPP and InnoDB
- Convert MyISAM to InnoDB
- Using tmpfs for mysqldump & mysqlimport
- Convert from INNODB to MYISAM
- Analyse slow-query-log using mysqldumpslow & pt-query-digest
- mysqlcheck with cron to optimize automatically
- Using MySQLTuner to Optimize MySQL configuration
-
-
- Directly connect to PHP-FPM
- Generating core-dump for php5-fpm
- GeoIP
- Having php5 and php7 on same system.
- Install Xdebug and configure it with webgrind
- Installation of PHP Code Review Tools
- memcache
- PHP's Zend Opcache Config & Web Viewer
- Setting Sqlite support with PHP
- Using HHVM with PHP-FPM Fallback
- Using Redis for PHP Sessions on Ubuntu Server
- Installing PhpMyAdmin Quickly
- Moving PHP's session storage to tmpfs
- Install Xdebug and configure it with Netbeans
- Nginx – Enable PHP-FPM Status Page
- PHP-FPM: Socket vs TCP/IP and sysctl tweaking
- APC Cache Optimization & Monitoring Using Web Interface
- Checking if PHP/WordPress can send mails
- Debugging PHP Scripts Using slow_log and more
- Increase file upload size limit in PHP-Nginx
- Increase PHP script execution time with Nginx
-
- Performance Optimization
- Remove Query string of css/js files
- Setup ElasticSearch with ElasticPress
- Using Redis for WordPress Object-Cache
- WooCommerce Window Shopping Caching Technique
- Moving WordPress To New Server (Faster)
- Better wp-cron using linux's crontab
- 404 error- Page not Found!!!
- Debugging WordPress with Nginx
Setup slow_log for PHP scripts
Setup error_log for PHP scripts
Important for Nginx Users
Setup FPM error_log to debug FPM itself
Confirm Changes…
Monitoring log file
Debugging PHP Scripts Using slow_log and more
If you are an old PHP programmer, you must have used PHP’s error_log function sometime. But PHP itself does not provide a way to find out slowly executing scripts. Slow scripts are not the ones which break your site but they slow-down everything. Using FPM, we can have a slow_log for all such scripts. Let’s see how to use these logs to debug PHP scripts. Also, we will see how PHP’s error_log gets diverted if it is running behind FPM and Nginx.
Setup slow_log for PHP scripts
Open… vim /etc/php5/fpm/pool.d/www.confMake necessary changes to match following values:
slowlog = /var/log/php5/slow.log
request_slowlog_timeout = 10s
You can replace 10s with any other value. This will help us find scripts which execute slowly. Image resizing function, network I/O related functions are some examples which will frequently show-up in PHP slow_log. Its up to you to debug them or ignore them based on your context.
Setup error_log for PHP scripts
When running PHP using FPM, we can override any php.ini setting from FPM. Open… vim /etc/php5/fpm/pool.d/www.confScroll down towards bottom and uncomment/change following 3 lines to match values given below:
php_admin_value[error_log] = /var/log/php5/error.log
php_admin_flag[log_errors] = on
Please note that turning on display_errors can break ajax-based applications. So be really careful with this.
Important for Nginx Users
You will not see a file/var/log/php5/error.log or not any error being logged in that file. Errors in your PHP scripts for a site will go intoerror_log specified for that site in its nginx config. Most likely: /var/www/example.com/logs/error.log file If you haven’t specified any error_log path for your site, then PHP errors will go to Nginx’s default error_log. Most likely /var/log/nginx/error.log file) You can find more details here about debugging with Nginx.
Setup FPM error_log to debug FPM itself
FPM is separate process. Like others, it can run into errors itself! FPM’s error_log is on by default but we will change its path to meet our convention. Open… vim /etc/php5/fpm/php-fpm.conf Make sureerror_log value looks like below
error_log = /var/log/php5/fpm.log
Please note that this error_log is not related to PHP’s error_log function described before.
Confirm Changes…
Create php5 log directory so we can have all PHP logs in one place:
mkdir /var/log/php5/
Restart PHP-FPM for changes to take effect…
service php5-fpm restart
Monitoring log file
Best way to open a separate shell on your server and use tail -f command to monitor logs… As we have multiple log files to monitor, you can simply use following command to monitor all of them together…
tail -f /var/log/php5/*.log
slow_log helped us many times to eliminate bottlenecking from our applications.
Always remember to turn it off when you are done with debugging. Leaving slow_log on is not a good idea.
Checking if PHP/WordPress can send mails
PREVIOUS
Increase file upload size limit in PHP-Nginx
NEXT
Features
- Server Setup & Management
- Site Creation & Management
- Create WP Cloud Sites
- Speed & Caching
- Firewall Protection
- Backups & Recovery
- Logs & Monitoring
- Deployments & Developer Tools
- Team Access & User Permissions
Useful Links
Product
Other Products
Subscribe for curated product updates, tips, and announcements.
"*" indicates required fields
This field is for validation purposes and should be left unchanged.
Email*
SIGN ME UP
Δ
© rtCamp, since 2009. All rights reserved.
