Example of writing phperror_log error information to a file-PHP source code

Source: Internet
Author: User
Tags php syntax error
Phperror_log error information if we want to analyze logs, We need to generate a log file and save it to the database or file. Here we take the file writing as an example, next let's take a look at the php error_log error information. If we want to analyze the log, We need to generate a log file and save it to the database or file. Here we take the file writing as an example. Next let's take a look at it.

Script ec (2); script

During development, display_errors and error_reporting are basically enabled to improve development efficiency. After going online, the page error is basically closed and the error message is put into the file.

1. php-fpm error_log Configuration

1. Modify php. ini.

Display_errors = Off // Changes to off, so no error message is reported during page access.

2. Modify the php-fpm configuration file.

; Php_flag [display_errors] = off
Php_admin_value [error_log] =/var/log/php-fpm/www-error.log
Php_admin_flag [log_errors] = on

Restart php-fpm. Note that the configuration of php-fpm replaces the configuration in php. ini. display_errors can also be configured in php-fpm. In this way, no error information is reported on the page, and the error information is recorded in the file.

2. Configure error_log in the command line and modify php. ini.

Display_errors = Off
Log_errors = On
Error_log =/var/log/cron/error. log

Run the following command:

[Root @ network www] # php test. php // test. php syntax error

In the command line, php-fpm configuration is not called, so we can only modify the content of php. ini. After modification, php does not need to be restarted. After the command is executed, the error message is written to the error. log file. This is suitable for the php script of crontab.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.