php PHP的console.log,console.error?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6717991/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 01:04:07  来源:igfitidea点击:

console.log, console.error for PHP?

php

提问by nami

When developing web applications, at the clientside level I use console.log and console.error to help me see what's going on. I am looking for a similar feature at the serverside level to help me see what's going on. I have seen error_log which writes errors to the server's log file and wanted to know if there is a similar function for writing to the servers access logs?

在开发 Web 应用程序时,在客户端级别我使用 console.log 和 console.error 来帮助我了解发生了什么。我正在寻找服务器端级别的类似功能,以帮助我了解发生了什么。我已经看到 error_log 将错误写入服务器的日志文件,想知道是否有类似的功能可以写入服务器访问日志?

Or am I going about this the wrong way, am I supposed to be using something completely different to see what's going on in the background for serverside development?

或者我是否以错误的方式解决这个问题,我是否应该使用完全不同的东西来查看服务器端开发的后台发生了什么?

采纳答案by Spudley

It's not quite the same thing, but you might want to investigate the PHP debugger, XDebug.

这并不完全相同,但您可能想研究 PHP 调试器XDebug

It has some very powerful debugging features for PHP. For example, you can step through a PHP program line by line and watch where it goes, and what the variables are set to at any given point in the program, etc.

它有一些非常强大的 PHP 调试功能。例如,您可以逐行执行 PHP 程序并观察它运行到哪里,以及在程序中的任何给定点设置了哪些变量,等等。

It works best when used in conjunction with an IDE such as Netbeans or Eclipse, as you can use the same interface to debug your programs as you use to edit your code.

它与 Netbeans 或 Eclipse 等 IDE 结合使用时效果最佳,因为您可以使用与编辑代码相同的界面来调试程序。

It can also generate trace files, which can be loaded into a program called WinCacheGrind, which allows you to trace through the program after it's run, to see, for example, which functions caused it to run slowly.

它还可以生成跟踪文件,这些文件可以加载到一个名为 WinCacheGrind 的程序中,该程序允许您在程序运行后进行跟踪,例如查看哪些函数导致它运行缓慢。

回答by user2961602

This worked for me: http://www.paulund.co.uk/output-php-data-in-browser-console

这对我有用:http: //www.paulund.co.uk/output-php-data-in-browser-console

/**
 * Send debug code to the Javascript console
 */ 
function debug_to_console($data) {
  if(is_array($data) || is_object($data)) {
    echo("<script>console.log('PHP: ".json_encode($data)."');</script>");
  } else {
    echo("<script>console.log('PHP: $data');</script>");
  }
}

回答by ssapkota

As an option you might also want to look at syslog()

作为一个选项,您可能还想查看syslog()

回答by prodigitalson

I second Spudley's answerabout using XDebug or the Zend Debugger (similar setup and operation to XDebug). However to directly answer your question you can use trigger_errorin combo with E_USER_WARNINGor E_USER_NOTICEand the appropriate error_reporting level. You could also use syslogas ssapkotasuggests.

我第二次回答 Spudley关于使用 XDebug 或 Zend Debugger(类似于 XDebug 的设置和操作)的回答。但是,要直接回答您的问题,您可以trigger_errorE_USER_WARNINGE_USER_NOTICE以及适当的 error_reporting 级别结合使用。您也可以syslog按照ssapkota 的建议使用。