Go to file
以诺书 af904671ad first commit 2024-02-25 19:55:17 +08:00
src first commit 2024-02-25 19:55:17 +08:00
composer.json first commit 2024-02-25 19:55:17 +08:00
readme.md first commit 2024-02-25 19:55:17 +08:00

readme.md

Webman-Dnsclient

  • The English version of this document is machine translated and for reference only

Webman的DNS客户端扩展。目前主要用于实现PHP原生不支持的向自定义DNS服务器发送请求通过本插件可以实现对自定义DNS服务器发送请求同时采用异步方案性能相比原生函数快3~5倍。 DNS client extension for Webman. At present, it is mainly used to send DNS requests to custom dns servers that are not supported by PHP native functions. Through this plug-in, it can send requests to custom DNS servers. At the same time, it adopts asynchronous scheme, and the performance is 3~5 times faster than the native function.

这是对Workerman协议扩展Dnsclient(for Workerman)在Webman下的封装 This is an encapsulation of the Workerman protocol extension Dnsclient(for Workerman) under Webman

安装Installation

首先你需要PHP环境和Composer具体方式请自行百度 First you need the PHP environment and Composer, please ask Google for details

由于这是一个Webman插件需要安装Webman Since this is a Webman plug-in, you need to install Webman composer composer create-project workerman/webman cd webman

此外需要用到Redis你需要确保PHP-Cli安装了redis扩展、以及一个Redis服务器同时安装Webman的Redis扩展。 In addition, in order to use Redis, you need to make sure that PHP-Cli has the redis extension installed, as well as a Redis server, as well as the Redis extension for Webman. composer require -W illuminate/redis illuminate/events

最后,安装本插件 Finally, install this plug-in composer require laysense/dnsclient

配置文件Configuration

配置文件位于 The configuration file is located in config/plugin/laysense/dnsclient/app.php

内容类似如下 Content similar to the following

<?php
return [
    'enable' => true,
    'DefaultServer'=>'119.29.29.29',
    'DefaultTimeout'=>3,
    'RedisExpire'=>10
];

DefaultServer是当未传入DNS服务器时默认的DNS请求服务器 DefaultTimeout是默认请求超时时间单位未秒 RedisExpire是获得请求值之后存入Redis后自动销毁的时间单位为秒。如需要永久保存请改为-1 DefaultServer is the default DNS request server when no DNS server is passed in DefaultTimeout Indicates the timeout period of the request, in seconds RedisExpire is the automatic destruction time after obtaining the requested value and storing it in Redis, in seconds. For permanent storage, change to -1

您还需要配置redis请在config/redis.php新增一个名为dnsc的Redis配置 You also need to configure redis, add a redis configurationdnsc in config/redis.php

<?php

return [
	 'default' => [
        *****(Your Default Redis Configuration)
    ],
    'dnsc' => [
        'host' => '127.0.0.1',
        'password' => null,
        'port' => 6379,
        'database' => 0,
    ],
];

请将127.0.0.1、null、6379、0等改为您实际的Redis服务器配置 Please change 127.0.0.1, null, 6379, 0, etc. to your actual Redis server configuration

示例Examples

#app/controller/IndexController.php
<?php

namespace app\controller;

use support\Request;
use support\Redis;
use Laysense\Dnsclient\Client;

class IndexController
{
    public function index(Request $request)
    {
        $dns=new Client();
        $id=$dns->server('8.8.8.8')->domain('laysense.com')->query('A');
        return redirect('/index/?id='$id);
    }
    public function get(Request $request)
    {
        $id='dnsc_'.$request->input('id');
        $redis = Redis::connection('dnsc');
        if($redis->exists($id)=='1'){
            return json(json_decode($redis->get($id)));
        }else{
            return 'NotFound';
        }
    }
}

##作者 Author 上海来笙信息科技有限公司(Shanghai Laysense Information Technology Co. Ltd.) mail: public@laysense.cn ##Copyright&License http://www.apache.org/licenses/ Apache License, Version 2.0

Current version

  • 2024/02/25 0.0.1