crcms / client
CRCMS Client
Installs: 197
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
pkg:composer/crcms/client
Requires
- php: >=7.1
- crcms/connection-pool: dev-master
- guzzlehttp/guzzle: ^6.3
- psr/http-message: ~1.0
This package is auto-updated.
Last update: 2025-10-14 22:48:13 UTC
README
使用方法
加载引入
如果您的Larvel版本>5.5可忽略此设置
在config/app.php中增加
'providers' => [
    CrCms\Foundation\ConnectionPool\PoolServiceProvider::class,
    CrCms\Foundation\Client\ClientServiceProvider::class,
]
增加配置
在config/client.php的connections中增加如下测试配置
'http' => [
    'driver' => 'http',
    'host' => 'blog.crcms.cn',
    'port' => 80,
    //资源连接器的配置,请参考guzzlehttp
    'settings' => [
        'timeout' => 1,
    ],
],
调用方法
//实例化并设置连接
$client = $this->app->make('client.manager')->connection('http');
//发送请求
$client = $client->request('/',[]);
//获取当前连接
dump(get_class($client->getConnection()));
//获取连接池管理器
dump(get_class($client->getConnectionPoolManager()));
//获取当前的连接资源的响应
dump(get_class($client->getResponse()));
//获取资源响应内容
dd($client->getContent());
动态化配置
$client = $this->app->make('client.manager')->connection([
    'name' => 'http',
    'driver' => 'http',
    'host' => '192.168.1.12',
    'port' => 8500,
    'settings' => [
        'timeout' => 1,
    ],
]);
使用连接池
在config/pool.php的connections中增加配置(可选增加)
'client' => [
    'max_idle_number' => 50,//最大空闲数
    'min_idle_number' => 15,//最小空闲数
    'max_connection_number' => 20,//最大连接数
    'max_connection_time' => 3,//最大连接时间(s)
],
使用连接池时,以当前连接名称做为连接池名称
支持的类型
- Http
后期增加
- Tcp
- WebSocket