Properties

$__useCount

$__useCount : integer

Type

integer — 作用计数

$__genTime

$__genTime : integer

Type

integer — 创建时间

$__isContruct

$__isContruct : boolean

Type

boolean — 是否执行构造方法

$stdClass

$stdClass : \stdClass|null

Type

\stdClass|null — 对象模板

$dnsCache

$dnsCache : array

Type

array — DNS查询缓存

$headers

$headers : array

Type

array — 请求报头

$client

$client : \swoole_http_client

Type

\swoole_http_client — swoole http client

$urlData

$urlData : array

Type

array — 解析的URL结果

$dnsTimeout

$dnsTimeout : integer

Type

integer — DNS解析超时时间

$__isDestroy

$__isDestroy : boolean

Type

boolean — 销毁标志

$redisPools

$redisPools : array

Type

array — redis连接池

$mysqlPools

$mysqlPools : array

Type

array — mysql连接池

$redisProxies

$redisProxies : array

Type

array — redis代理池

$reflections

$reflections : array

Type

array — 反射类属性的默认值

$dnsExpire

$dnsExpire : integer

Type

integer — DNS缓存有效时间(秒)

$dnsTimes

$dnsTimes : integer

Type

integer — DNS缓存有效次数

Methods

__construct()

__construct(string  $url = '', integer  $timeout, array  $headers = array()) : \PG\MSF\Client\Http\Client

Client constructor.

Parameters

string $url

如http://domain.com:port,http://domain.com:port/path/

integer $timeout

域名解析超时时间,单位秒

array $headers

请求报头

Returns

\PG\MSF\Client\Http\Client

$this

__sleep()

__sleep() : array

在序列化及dump对象时使用,代表哪些属于需要导出

Returns

array

__unsleep()

__unsleep() 

和__sleep作用相反

getServerInstance()

getServerInstance() : \swoole_server

获取运行Server实例

Returns

\swoole_server

getConfig()

getConfig() : \Noodlehaus\Config

获取运行server实例配置对象

Returns

\Noodlehaus\Config

getPack()

getPack() : \PG\MSF\Pack\IPack

获取运行server实例打包对象

Returns

\PG\MSF\Pack\IPack

getRedisPool()

getRedisPool(string  $poolName) : boolean|\PG\AOP\Wrapper|\PG\MSF\Pools\CoroutineRedisProxy|\Redis

获取Redis连接池

Parameters

string $poolName

配置的Redis连接池名称

Returns

boolean|\PG\AOP\Wrapper|\PG\MSF\Pools\CoroutineRedisProxy|\Redis

getMysqlPool()

getMysqlPool(string  $poolName) : boolean|\PG\AOP\Wrapper

获取MySQL连接池

Parameters

string $poolName

配置的MySQL连接池名称

Returns

boolean|\PG\AOP\Wrapper

getRedisProxy()

getRedisProxy(string  $proxyName) : boolean|\PG\AOP\Wrapper|\PG\MSF\Pools\CoroutineRedisProxy|\Redis

获取Redis代理

Parameters

string $proxyName

配置的Redis代理名称

Throws

\Exception

Returns

boolean|\PG\AOP\Wrapper|\PG\MSF\Pools\CoroutineRedisProxy|\Redis

setRedisPools()

setRedisPools(array|null  $redisPools) : $this

设置RedisPools

Parameters

array|null $redisPools

多个Redis连接池实例,通常用于销毁Redis连接池,赋值为NULL

Returns

$this

setRedisProxies()

setRedisProxies(array|null  $redisProxies) : $this

设置RedisPools

Parameters

array|null $redisProxies

多个Redis代理实例,通常用于销毁Redis代理,赋值为NULL

Returns

$this

destroy()

destroy() 

销毁

isUse()

isUse() 

对象已使用标识

getIsDestroy()

getIsDestroy() : boolean

是否已经执行destroy

Returns

boolean

setContext()

setContext(\PG\MSF\Helpers\Context  $context) : $this

设置上下文

Parameters

\PG\MSF\Helpers\Context $context

请求上下文对象

Returns

$this

setHeaders()

setHeaders(array  $headers) : $this

设置请求报头

Parameters

array $headers

键值对应数组的报头列表

Returns

$this

getHeaders()

getHeaders() : array

获取当前请求报头

Returns

array

setCookies()

setCookies(array  $cookies) : $this

设置请求Cookies

Parameters

array $cookies

键值对应数组的Cookie数据

Returns

$this

asyncDnsLookup()

asyncDnsLookup(callable  $callBack, array  $headers = array()) 

异步DNS查询

Parameters

callable $callBack

DNS查询异步回调函数

array $headers

键值对应数组的报头列表

Throws

\Exception

goDnsLookup()

goDnsLookup(string  $url = '', integer  $timeout, array  $headers = array()) : \PG\MSF\Coroutine\Dns|$this

运行DNS查询协程

Parameters

string $url

https://www.baidu.com

integer $timeout

协程超时时间

array $headers

额外的报头

Returns

\PG\MSF\Coroutine\Dns|$this

goPost()

goPost(string  $url = '', array  $data = array(), integer  $timeout = 30000, array  $headers = array()) : \PG\MSF\Coroutine\Http

在完成DNS查询的基础上,运行POST请求协程

Parameters

string $url

请求的URL

array $data

POST的数据

integer $timeout

请求超时时间

array $headers

额外的报头

Throws

\Exception

Returns

\PG\MSF\Coroutine\Http

goGet()

goGet(string  $url = '', array  $query = null, integer  $timeout = 30000, array  $headers = array()) : \PG\MSF\Coroutine\Http

在完成DNS查询的基础上,运行GET请求协程

Parameters

string $url

请求的URL

array $query

POST的数据

integer $timeout

请求超时时间

array $headers

额外的报头

Throws

\Exception

Returns

\PG\MSF\Coroutine\Http

goSinglePost()

goSinglePost(string  $url = '', array  $data = array(), integer  $timeout = 30000, array  $headers = array()) : \PG\MSF\Coroutine\Http

单个独立POST请求协程(自动完成DNS查询、获取数据)

Parameters

string $url

请求的URL

array $data

POST的数据

integer $timeout

请求超时时间

array $headers

额外的报头

Throws

\Exception

Returns

\PG\MSF\Coroutine\Http

goSingleGet()

goSingleGet(string  $url = '', array  $query = null, integer  $timeout = 30000, array  $headers = array()) : \PG\MSF\Coroutine\Http

单个独立GET请求协程(自动完成DNS查询、获取数据)

Parameters

string $url

请求的URL

array $query

POST的数据

integer $timeout

请求超时时间

array $headers

额外的报头

Throws

\Exception

Returns

\PG\MSF\Coroutine\Http

goConcurrent()

goConcurrent(array  $requests) : array

并行POST或者Get请求协程(自动完成DNS查询、获取数据)

Parameters

array $requests

格式如:

[
  [
     // 必须为全路径URL
    'url'         => 'http://www.baidu.com/xxx',
    'method'      => 'GET', // 默认GET
    'dns_timeout' => 1000, // 默认为30s
    'timeout'     => 3000,  // 默认不超时
    'headers'     => [],    // 默认为空
    'data'        => ['a' => 'b'] // 发送数据
  ],
  [
    'url'         => 'http://www.baidu.com/xxx',
    'method'      => 'POST',
    'timeout'     => 3000,
    'headers'     => [],
    'data'        => ['a' => 'b'] // 发送数据
  ],
  [
    'url'         => 'http://www.baidu.com/xxx',
    'method'      => 'POST',
    'timeout'     => 3000,
    'headers'     => [],
    'data'        => ['a' => 'b'] // 发送数据
  ],
];
                                  

Throws

\Exception

Returns

array

dnsLookupCallBack()

dnsLookupCallBack(  $ip) : boolean

DNS查询返回时回调

Parameters

$ip

string 主机名对应的IP

Returns

boolean

parseUrl()

parseUrl(string  $url) : boolean|mixed

标准化解析URL

Parameters

string $url

待解析URL

Returns

boolean|mixed

get()

get(string  $path, array  $query,   $callback) 

发起异步GET请求

Parameters

string $path

待请求的URL Path

array $query

查询参数

$callback

post()

post(string  $path, array  $data,   $callback) 

发起异步POST请求

Parameters

string $path

待请求的URL Path

array $data

发送的POST数据

$callback

setDnsCache()

setDnsCache(string  $host, string  $ip) 

设置DNS缓存

Parameters

string $host

HOST名称

string $ip

已解析的IP

clearDnsCache()

clearDnsCache(  $host) 

清除HOST对应的DNS缓存

Parameters

$host

HOST名称

getDnsCache()

getDnsCache(string  $host) : mixed|null

获取DNS缓存

Parameters

string $host

HOST名称

Returns

mixed|null