firePHP php debugging tools of

  PHP can make use of the same browser as js console debugging code ------- FirePHP

1. Install the plug-FirePHP

  In the Chrome browser app store, search for keywords firephp, in the list of plug-out, select the first one, add it to Chrome.

 

 

2. Get FirePHP library

  FirePHP just installed browser plug-in is not enough, we also need to install its server, FirePHP library Download: http://www.firephp.org

 

 

 

 

  Download the corresponding language version of the library file, the download is complete, the compressed package fb.php and FirePHP.class.php two files are copied to our project

 

   The introduction can be used in the project

 

3. Use

  Example:

<?php

namespace Common\Lib\Util;

if (!class_exists('FB')) {

    vendor('FirePHP.fb');

}



class FireBug {

    /**

    * 将php调试信息打印到控制台

    * @param mixes $object : 待输出的数据,类型可以是字符串、数组或者对象

    * @param string $label : 标题

    * @param boolean $showTrace : 是否显示调用跟踪信息

    */

    public static function console($object, $label=null, $showTrace=false)
    {
        //开发与生产模式的开关标识,我们只在开发模式下调试脚本
        if (!DEBUG_PHP) {
            return;
        }

        try {
            $label = $label ? $label : time();
            \FB::log($object,$label);
            if (is_array($object) || is_object($object)) {
                $headers = array_keys(reset($object));
                if (is_array($headers)) {
                    array_unshift($object,$headers);
                    \FB::table($label,$object);
                }else{
                    \FB::table($label,array(array_keys($object),$object));
                }

            }else if(is_object($object)){
                \FB::table($label,$object);
            }

            if ($showTrace) {
                \FB::trace($label);
            }

        } catch (Exception $e) {
            echo '请开启输出缓冲函数ob_start()';
        }

    }

}

 

   

fb('Hello World');
        fb('log message', \FirePHP::LOG);
        fb('Info message' ,\FirePHP::INFO);
        fb('Warn message' ,\FirePHP::WARN);
        fb('Error message',\FirePHP::ERROR);


        fb('Message with label','Label',\FirePHP::LOG);

        fb(array('key1'=>'val1',
            'key2'=>array(array('v1','v2'),'v3')),
            'TestArray',\FirePHP::LOG);

        fb('Backtrace to here',\FirePHP::TRACE);

        fb(array('2 SQL queries took 0.06 seconds',array(
           array('SQL Statement','Time','Result'),
           array('SELECT * FROM Foo','0.02',array('row1','row2')),
           array('SELECT * FROM Bar','0.04',array('row1','row2'))
          )),\FirePHP::TABLE);

        /* Will show only in "Server" tab for the request */
        fb(apache_request_headers(),'RequestHeaders',\FirePHP::DUMP);

效果展示:

  

 

 

 

是不是非常方便,通过FirePHP,我们就不需要把调试信息用echo,print_r或者日志的形式输出了

 

Guess you like

Origin www.cnblogs.com/xingxia/p/phptool_firephp.html