Php 使用池时如何修复HTTP\Exception\ServerException?
假设我可以创建一个池,任何失败的请求都应该调用“拒绝”方法,但是我得到的是Php 使用池时如何修复HTTP\Exception\ServerException?,php,guzzle,Php,Guzzle,假设我可以创建一个池,任何失败的请求都应该调用“拒绝”方法,但是我得到的是GuzzleHttp\Exception\ServerException。这是我的密码: $client = new GuzzleHttp\Client([ 'base_uri' => ServerConfig::Json('file_server'), ]); $requests = function() use ($client, $delete_time) { foreach($this-&g
GuzzleHttp\Exception\ServerException
。这是我的密码:
$client = new GuzzleHttp\Client([
'base_uri' => ServerConfig::Json('file_server'),
]);
$requests = function() use ($client, $delete_time) {
foreach($this->pcs_master->pcs as $id => $pcs) {
$paths = $pcs->database->SelectSimpleArray('wopi_doc', 'wd_filepath', ['wd_deleted_at IS NOT NULL', 'wd_deleted_at < ?' => $delete_time]);
if ($paths) {
foreach (array_chunk($paths, self::WOPI_SOFT_DELETE_CHUNK_SIZE) as $chunk) {
yield $client->delete('/', [
'body' => json_encode(['paths' => $files]),
]);
}
}
}
};
$pool = new GuzzleHttp\Pool($client, $requests(), [
'concurrency' => self::WOPI_SOFT_DELETE_MAX_CONCURRENT_REQUESTS,
'fulfilled' => function ($response, $index) {
dump('fulfilled', $response, $index);
},
'rejected' => function ($reason, $index) {
dump('rejected', $reason, $index);
},
]);
$pool->promise()->wait();
看起来异常被抛出到
$client->delete
行,但我认为应该创建一个请求
对象,但还没有发送它(这是池的工作)出于某种原因,我似乎必须将承诺包装到函数中:
foreach (array_chunk($paths, self::WOPI_SOFT_DELETE_CHUNK_SIZE) as $chunk) {
yield function() use ($client, $files) {
return $client->deleteAsync('/', [
'body' => json_encode(['paths' => $files]),
]);
};
}
client::get()、client::put()、client::post()、client::delete()
是client::request()
的抽象,它本身就是client::requestAsync()的抽象。
您正试图生成一个ResponseInterface
实例。
如果要使用GuzzleHttp\Pool
,则必须手动创建Psr\http message\Request
对象
yield new GuzzleHttp\Psr7\Request($method, $uri, $headers_array, $body, $protocol_version);
更多信息可通过签出和
编辑:回复评论中的问题。
最终,您希望发送的每个请求都将使用
Client::sendsync()
发送。这意味着以前在客户端中配置的任何选项在池中使用时都将保持有效。没有办法利用$Client
对象,该对象为我设置基本uri
和其他默认值,以在使用池?更新响应时包括注释答案。
yield new GuzzleHttp\Psr7\Request($method, $uri, $headers_array, $body, $protocol_version);