php console log speed

时间:2013-12-27 作者:incrs

如何在php中将速度基准记录到控制台?我不想echo 结果供用户查看,但只是在某种日志中。

我知道我可以用this:

$first  = new DateTime( \'11:35:20\' );
$second = new DateTime( \'12:00:45\' );

$diff = $first->diff( $second );

echo $diff->format( \'%H:%I:%S\' ); // -> 00:25:25
但我想记录时间,而不是echo 信息技术我是否使用错误日志?

1 个回复
SO网友:bueltge

如果您要在浏览器的控制台中编写,那么可以使用许多帮助程序中的一个,或者使用php中的一个小型自定义函数。follow功能易于使用,并且可以在浏览器的控制台中进行登录。

if ( ! function_exists( \'debug_to_console\' ) ) {
    /**
     * Simple helper to debug to the console
     * 
     * @param  object, array, string $data
     * @return string
     */
    function debug_to_console( $data ) {

        $output = \'\';
        $output .= \'console.info( \\\'Debug in Console:\\\' );\';
        $output .= \'console.log(\' . json_encode( $data ) . \');\';

        echo \'<script>\' . $output . \'</script>\';
    }
}
图片说明更多:enter image description here

或者使用库,如ChromePHP 对于铬项目,Webug 对于许多不同的浏览器或FirePHP 例如。在这个话题上给更多的帮助。

如果您将在WordPress中使用此插件,那么它是一个快速且易于使用的助手Debug Objects, 该插件的源代码来自插件内部的上述易用函数以及CromePHP库。

结束

相关推荐

Displaying oEmbed errors?

有时,通过oEmbed嵌入项目是不可能的,例如,当YouTube视频已禁用嵌入时。The oEmbed service will return a 401 Unauthorized, 并且不会转换代码。有没有办法通知用户这一点?当前的工作流是非直观的(至少对我来说),我更喜欢在WordPress页面上,或者更好的是,在编辑器中显示一条消息,说明对象无法嵌入。