How do i log errors and warnings into a file in php?

 Posted in PHP

How to Log Errors and Warnings[into error.log file] in a PHP

This is a quick post on error logging in PHP. The reason for sharing this small tip is I found it can be helpful for users to track the errors or debug the errors which are thrown in the background.

Recently, I was working on integrating Facebook chatbot for one of our clients. While developing a Facebook chatbot we need to set up a webhook to which Facebook sends a user’s message in the background. Then our code should respond back on the basis of the message.

For some reason, our app was not responding back to the users. This whole process operates in the background and I got stuck on the problem for almost 2 hours.

Then suddenly I got an idea of logging the errors in a file so I can track what is wrong with the code. And then I was able to track errors and resolved all the problems. Without error logs, I couldn’t solve my problem as I was in a completely wrong direction.

Place the below code in your configuration file which will create an error.log file in your root directory.

Bài mới nhất

Chủ Đề