Home > Backend Development > PHP Tutorial > Is there any good function in PHP to output Log to the console for debugging?

Is there any good function in PHP to output Log to the console for debugging?

WBOY
Release: 2016-07-06 13:52:03
Original
1080 people have browsed it

Similar to JS's console.log(); you can add it to the php code line and watch the console Log for debugging, so that it does not affect the normal program operation.

Reply content:

Similar to JS's console.log(); you can add it to the php code line and watch the console Log for debugging, so that it does not affect the normal program operation.

Reference an external php file chromePhp
Usage:

<code>include 'ChromePhp.php';
ChromePhp::log('Hello console!');
ChromePhp::log($_SERVER);
ChromePhp::warn('something went wrong!');</code>
Copy after login

In this way, you can see the information in the chrome browser console. Haven't tried it on Firefox.

First of all, JavaScript can be parsed in the browser environment, but PHP cannot. It requires a parser such as Apache and php-cgi, so it is unrealistic for you to want PHP to run under the control of the browser.

When debugging, you can use functions such as echo, print_r, var_dump to output the results to the page,

Of course you can also follow the xdebug debugging tool to support breakpoint debugging

Let me talk about the debugging methods I commonly use:

<code>file_put_contents('log.txt',var_export($_POST,true));
//这样不会中断程序的运行</code>
Copy after login

https://craig.is/writing/chrome-logger

Yes, monolog works with chromephp extension

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template