PHP code example of luofei614 / socketlog

1. Go to this page and download the library: Download luofei614/socketlog library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

luofei614 / socketlog example snippets


    
    // 根据实际情况,确定源码的 php 目录放置位置,在需要调试的文件中引入
    

    
    lo world');
    

    slog('msg', 'log');    // 一般日志
    slog('msg', 'error');  // 错误日志
    slog('msg', 'info');   // 信息日志
    slog('msg', 'warn');   // 警告日志
    slog('msg', 'trace');  // 输出日志,同时会打出调用栈
    slog('msg', 'alert');  // 将日志以alert方式弹出
    slog('msg', 'log', 'color:red;font-size:20px;'); // 自定义日志的样式,第三个参数为 css 样式
    

    
          array(
            'enable'              => true,        // 是否打印日志, [true | false]
            'host'                => 'localhost', // WebSocket 服务器地址,默认为 localhost
            'optimize'            => false,       // 是否显示有利于程序优化的信息,如运行时间、吞吐率、消耗内存等,默认为 false
            'show_     ),
        'config'
    );
    

            slog(
                array(
                    'allow_client_ids' => array('luofei_zfH5NbLn', 'easy_DJq0z80H')    // 可设置多个 cliet_id
                ),
                'set_config'
            );
            

            
                  array(
                    'force_client_id' => 'luofei_zfH5NbLn'    // 只可设置一个 cliet_id
                ),
                'config'
            );
            slog('test');
            

    
    k\org\Slog;

    // 配置 SocketLog
    Slog::config(
        array(
            'enable'              => true,        // 是否打印日志, [true | false]
            'host'                => 'localhost', // WebSocket 服务器地址,默认为 localhost
            'optimize'            => false,       // 是否显示有利于程序优化的信息,如运行时间、吞吐率、消耗内存等,默认为 false
            'show_
    Slog::error('msg');    // 错误日志
    Slog::info('msg');     // 信息日志
    Slog::warn('msg');     // 警告日志
    Slog::trace('msg');    // 输出日志,同时会打出调用栈
    Slog::alert('msg');    // 将日志以 alert 方式弹出
    Slog::log('msg', 'log', 'color:red;font-size:20px;');  // 自定义日志的样式,第三个参数为 css 样式
    

    $link = mysql_connect('localhost:3306', 'root', '123456', true);
    mysql_select_db('kuaijianli', $link);

    $sql = "SELECT * FROM `user`";

    slog($sql, $link);
    

        $headers = array();
        if (isset($_SERVER['HTTP_USER_AGENT'])) {
            $headers[] = 'User-Agent: ' . $_SERVER['HTTP_USER_AGENT'];
        }

        if (isset($_SERVER['HTTP_SOCKETLOG'])) {
            $headers[] = 'Socketlog: ' . $_SERVER['HTTP_SOCKETLOG'];
        }

        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        

    
         array(
            'error_handler'       => true,
            'optimize'            => true,
            'show_

    slog($this->queryStr, $this->_linkID);