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
WBOYOriginal
2016-07-06 13:52:031079browse

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>

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>

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

Yes, monolog works with chromephp extension

Statement:
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