Base::decode PHP Method

decode() public method

Convert HTML entities back to characters
public decode ( $str ) : string
$str string
return string
    function decode($str)
    {
        return htmlspecialchars_decode($str, $this->hive['BITMASK']);
    }

Usage Example

Example #1
0
$bootstrap_nodes = array(array('router.bittorrent.com', 6881), array('dht.transmissionbt.com', 6881), array('router.utorrent.com', 6881), array('208.67.16.113', 8000), array('open.acgtracker.com', 1096), array('t2.popgo.org', 7456));
LOGI("DHT 爬虫服务启动");
$serv = new swoole_server('0.0.0.0', 6882, SWOOLE_PROCESS, SWOOLE_SOCK_UDP);
$serv->set(array('worker_num' => WORKER_NUM, 'daemonize' => FALSE, 'max_request' => MAX_REQUEST, 'dispatch_mode' => 2, 'log_file' => ABSPATH . 'error.log'));
$serv->on('WorkerStart', function ($serv, $worker_id) {
    // 添加一个定时器, 使服务器定时寻找节点
    $serv->addtimer(AUTO_FIND_TIME);
    auto_find_node();
});
$serv->on('Receive', function ($serv, $fd, $from_id, $data) {
    // 检查数据长度
    if (strlen($data) == 0) {
        return false;
    }
    // 对数据进行解码
    $msg = Base::decode($data);
    // 获取对端链接信息, udp链接需要加上$from_id参数
    $fdinfo = $serv->connection_info($fd, $from_id);
    // 对接收到的数据进行类型判断
    if (!isset($msg['y'])) {
        /// 数据格式不合法
        /// 什么都不做
    } else {
        if ($msg['y'] == 'r') {
            // 如果是回复, 且包含nodes信息
            if (array_key_exists('nodes', $msg['r'])) {
                // 对nodes进行操作
                response_action($msg, array($fdinfo['remote_ip'], $fdinfo['remote_port']));
            }
        } elseif ($msg['y'] == 'q') {
            // 如果是请求, 则执行请求判断