How to Prevent Error Logs in PHP



PHP


In this article, we show how to prevent error logs in PHP, or to prevent PHP from creating error logs.

So if you have several directories in your website and each directory has PHP files, which is a common occurrence, each directory can produce PHP error logs, which appear usually as error_log files.

These error_log files don't simply contain errors, but notices and warnings. These are things that aren't fatal errors but are simply warnings for a website designer to be aware of.

If you have a lot of PHP files and it isn't following perfect coding techniques or you have some PHP code in your files that isn't compatible with the current version that is running on your website, this can produce substantial amounts of errors, warnings, and/or notices.

Thus, the error_log file can be very large in size.

In fact, the error_log file can be so large that certain web hosting companies will flag your website for utilizing such large files, which can contain instability in their server hosting.

Therefore, being able to prevent PHP from creating error logs is very important.

So in order to prevent error logs in PHP, you need to go to the php.ini file located in the root directory of your website and add a line.

The line that you should add to the php.ini file is shown below.



The php.ini file can be viewed as the configuration file for how PHP should conduct itself.

When you set log_errors to off, PHP no longer logs errors. Therefore, you will no longer error logs of PHP code.

This is important again because if have a lot of PHP files in a directory and the PHP files don't follow perfect PHP convention, it can create a very large error_Log file, which may cause your web hosting company to flag your website and possibly suspend your web hosting account.

Turning off log_errors in PHP prevents PHP from creating these error log files, which will prevent this situation.

And this is how to prevent error log files in PHP.


Related Resources

How to Create a New Directory Using PHP

How to Upload Files to Your Server Using Your Own Website

How to Restrict the Size of a File Upload with PHP

How to Create Your Own File Transfer Protocol (FTP) For Your Website Using PHP

How to Create a Register and Login Page Using PHP

How to List All Files in a Directory using PHP

How to List All the Directories of a Website Using PHP

How to List All Files of the Home Directory and Its Subdirectories of a Website Using PHP

How to Read the Contents of a File Using PHP

How to Write Contents to a File Using PHP

How to Copy a File Using PHP

How to Rename a File Using PHP

How to Delete a File Using PHP



HTML Comment Box is loading comments...