

Let’s say you created an online messaging platform and due to some unknown reason, users on your website weren’t able to receive messages from their friends. Let us understand this through an example.
#Php try catch echo console error message code
Just as you can run Python or Node.js code on a console in your terminal, and print results and log errors, the console in your browser allows you to run Javascript code and log information pertinent to your website. The browser console, as the name suggests, is a console in the browser. When something goes wrong on a website, usually the user is shown a fancy error message about what happened.īut a web developer’s window to what might have gone wrong is the browser’s Dev Tools - primarily the browser console. Let’s see how we can use that to our advantage. One of these Developer Tools, known as the browser’s console allows you to log messages and run Javascript code to debug your application. These tools allow you to inspect the DOM object, monitor network requests and responses, page load times, website performance, memory consumption and so much more. These are also known as the Developer Tools and can be accessed by right-clicking on the web-page and selecting the ‘Inspect’ option. Modern browsers came to the rescue and realized the importance of providing developers with the necessary tools to make way for some easy, yet powerful logging and debugging support. The aforementioned issues restrict logging capabilities not only for PHP but for any language that was going to be used for web development in the future. Conventional logging mechanisms possible in PHP can, therefore, seem less viable for more extensive, dynamic websites. Though static log files help in a retrospective analysis of how the execution unfolded, they can in some sense deprive you of the rich real-time experience of monitoring the dynamics of a modern website bustling with network requests and socket connections.Īlso, there is only so much information that you can log onto your web-page without disrupting it’s design. īoth these options can prove to be restrictive. By displaying variable values on web-pages using echo and var_dump.

By either writing to log files on the disk or.PHP can be used for logging through two primary ways. But there was hope!īefore that, let’s see how PHP natively supports logging and debugging. I was so used to working with the browser’s console for debugging, that having to work with PHP’s native logging support couldn’t fill that void. Though when I started programming in PHP, I realized that my background in Javascript had not prepared me for this. More than 25 years since its creation, PHP is still one of the most widely used programming languages in the world, accounting for about 78% of the known internet. We’ll see how logging is natively supported in PHP, and how doing it in the browser console has more to offer than printing logs on webpages or writing logs to files. In this post, we’ll see how we can refine our PHP web development practices by understanding the importance of logging to the browser console. In a company or a community setting, intelligent logging practices can help everyone to be on the same page about the status and the progress of the project. Not only does it make your project’s underlying execution more transparent and intelligible, but also more accessible in its approach. Logging is a key aspect of monitoring, troubleshooting and debugging your code.

“All code and no logging makes John a black box error-prone system.”
