Sender.php 1005 Bytes
<?php

error_reporting(E_ALL);
ini_set('display_errors',true);

/**
 * 读取配置信息
 */
$Config = new Lua();
$Config->include(__DIR__.'/Config.lua');

require_once __DIR__.'/Rabbitmq.php';

/**
 * 发送者类
 */
class Sender{
    
    /**
     * 添加到队列中
     * @param array $data
     * @param array $tags
     * @return type
     */
    static function pushmq($type,array $data,array $tags = []){
        $tags = $tags + array(
            'ip'=>'',
            'hostname'=>'',
        );
        return Rabbitmq::handle($type, $data, $tags);
    }
    
    /**
     * 写日志
     * @param type $message
     * @return type
     */
    static function log($message){
        global $Config;
        echo $message."\n";
        if (!$Config->log_file){
            return;
        }
        
        $fp = @fopen($Config->log_file,'a');
        if (!$fp){
            return;
        }
        $r = fwrite($fp, $message."\n");
        fclose($fp);
        
        return $r;
    }
}