| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 | <?phpclass RTDEBUG {    //Is debug on    private static $is_debug = false;    //    private static $fo       = null;    private static $pid      = -1;    private static $host     = '';    private static $uri      = '';    private static $port     = '';    //Log Type    const LEVEL_LOG     = 0;    const LEVEL_DEBUG   = 1;    const LEVEL_WARNING = 2;    const LEVEL_ERROR   = 3;    /**     * Init stream socket     * @param socketURL     * @param port     */    public static function init($host='',$uri='',$port=80){        if($host=='') return;        $fo = @fsockopen($host,$port,$errno,$errstr,30);        if(!$fo) return;        @stream_set_blocking($fp, 0);        self::$fo = $fo;        self::$host = $host;        self::$port = $port;        self::$uri = $uri;        self::$pid = time().rand(100000, 999999);        self::$is_debug = true;    }    /**     * @param msg require!!!     */    public static function addLog($msg,$level=0){        // print_r();        if(!self::$is_debug || !$msg) return false;        //Add last calling func. info        $_backtrace = debug_backtrace();        $data = '';        switch(gettype($msg)){            case 'array':            case 'object':                $data = array('data'=>$msg);                break;            default:                $data = array('msg'=>$msg);        }        $data['backtrace'] = array('file'=>str_replace($_SERVER['DOCUMENT_ROOT'], '', $_backtrace[0]['file']),'line'=>$_backtrace[0]['line']);        self::sendLog($data,$level);            }    private static function sendLog($data,$level){        if(!self::$is_debug || !$data || $data=='' || $level<0) return false;        $data = urlencode(json_encode($data));        $url = self::$uri.'?data='.$data.'&level='.$level.'&pid='.self::$pid.'&_t='.time().round(microtime()*1000,0);        $http = array(            'GET '.$url.' HTTP/1.1',            'Host: '.self::$host.':'.self::$port,            'Connection: close',            'User-Agent: RTDEBUG/1.0 RTDEBUG'        );        $request = join("\n",$http)."\n\n";        fputs(self::$fo,$request);        // fclose(self::$fo);    }}
 |