<commit_before><?php
/**
 * Created by PhpStorm.
 * User: hebidu
 * Date: 2017-08-14
 * Time: 14:21
 */

namespace sunsun\server\business;

/**
 * 用于检测业务代码死循环或者长时间阻塞等问题
 * 如果发现业务卡死，可以将下面declare打开（去掉//注释），并执行php start.php reload
 * 然后观察一段时间workerman.log看是否有process_timeout异常
 */
#declare(ticks=1);

date_default_timezone_set("Etc/GMT");
// 外部没有定义过则默认正式环境
if (!defined('SUNSUN_ENV')) {
    define("SUNSUN_ENV", "production");//debug|production 模式
}

use GatewayWorker\Lib\Gateway;
use sunsun\dal\DeviceTcpClientDal;
use sunsun\decoder\SunsunTDS;
use sunsun\helper\LogHelper;
use sunsun\model\DeviceTcpClientModel;
use sunsun\server\consts\SessionKeys;
use sunsun\server\db\DbPool;
use sunsun\server\factory\DeviceFacadeFactory;
use sunsun\server\tcpChannelCommand\CommandFactory;
use Workerman\Mqtt\Client;
use Workerman\Worker;

/**
 * 主逻辑
 * 主要是处理 onConnect onMessage onClose 三个方法
 * onConnect 和 onClose 如果不需要可以不用实现并删除
 */
class SlaveEvents
{
    /**
     * @var  \sunsun\server\db\DbPool
     */
    public static $dbPool;
    /**
     * @var Client
     */
    public static $mqttClient;
    private static $activeTime;//

    public static function onWorkerStart(Worker $businessWorker)
    {
        self::$dbPool = DbPool::getInstance();
        self::$mqttClient = new Client("mqtt://apollo.ssxiali.com:61613", [
            'username' => 'hebidu',
            'password' => '<PASSWORD>',
            'debug' => false
        ]);
        self::$mqttClient->onConnect = function (Client $mqtt) {
        };
        self::$mqttClient->onError = function (\Exception $exception) {
            self::sendEmailTo($exception->getFile().'_'.$exception->getLine().'_'.$exception->getMessage(), "mqtt error");
        };
        self::$mqttClient->connect();
    }

    public static function sendEmailTo($content, $title = 'Slave事件')
    {<commit_msg>[更新] Events.php<commit_after><?php
/**
 * Created by PhpStorm.
 * User: hebidu
 * Date: 2017-08-14
 * Time: 14:21
 */

namespace sunsun\server\business;

/**
 * 用于检测业务代码死循环或者长时间阻塞等问题
 * 如果发现业务卡死，可以将下面declare打开（去掉//注释），并执行php start.php reload
 * 然后观察一段时间workerman.log看是否有process_timeout异常
 */
#declare(ticks=1);

date_default_timezone_set("Etc/GMT");
// 外部没有定义过则默认正式环境
if (!defined('SUNSUN_ENV')) {
    define("SUNSUN_ENV", "production");//debug|production 模式
}

use GatewayWorker\Lib\Gateway;
use sunsun\dal\DeviceTcpClientDal;
use sunsun\decoder\SunsunTDS;
use sunsun\helper\LogHelper;
use sunsun\model\DeviceTcpClientModel;
use sunsun\server\consts\SessionKeys;
use sunsun\server\db\DbPool;
use sunsun\server\factory\DeviceFacadeFactory;
use sunsun\server\tcpChannelCommand\CommandFactory;
use Workerman\Mqtt\Client;
use Workerman\Worker;

/**
 * 主逻辑
 * 主要是处理 onConnect onMessage onClose 三个方法
 * onConnect 和 onClose 如果不需要可以不用实现并删除
 */
class SlaveEvents
{
    /**
     * @var  \sunsun\server\db\DbPool
     */
    public static $dbPool;
    /**
     * @var Client
     */
    public static $mqttClient;
    private static $activeTime;//

    public static function onWorkerStart(Worker $businessWorker)
    {
        self::$dbPool = DbPool::getInstance();
        self::$mqttClient = new Client("mqtt://apollo.ssxiaoli.com:61613", [
            'username' => 'hebidu',
            'password' => '<PASSWORD>',
            'debug' => false
        ]);
        self::$mqttClient->onConnect = function (Client $mqtt) {
        };
        self::$mqttClient->onError = function (\Exception $exception) {
            self::sendEmailTo($exception->getFile().'_'.$exception->getLine().'_'.$exception->getMessage(), "mqtt error");
        };
        self::$mqttClient->connect();
    }

    public static function sendEmailTo($content, $title = 'Slave事件')
    {
{'fraction_non_alphanumeric': 0.1461767089975682, 'fraction_numerical': 0.009727100783572008, 'mean_word_length': 3.4441776710684273, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2223709', 'n_tokens_mistral': 1393, 'n_tokens_neox': 1446, 'n_words': 213}