で拒否された同時要求の応答: http://docs.guzzlephp.org/en/latest/quickstart.html#concurrent-requestsアクセス私はがつがつ食う同時実行要求ツールを使用していますがつがつ食う
私のコードは、サンプルコードに似ています
use GuzzleHttp\Pool;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
$client = new Client();
$requests = function ($total) {
$uri = 'http://127.0.0.1:8126/guzzle-server/perf';
for ($i = 0; $i < $total; $i++) {
yield new Request('GET', $uri);
}
};
$pool = new Pool($client, $requests(100), [
'concurrency' => 5,
'fulfilled' => function ($response, $index) {
// this is delivered each successful response
},
'rejected' => function ($reason, $index) {
// this is delivered each failed request
},
]);
// Initiate the transfers and create a promise
$promise = $pool->promise();
// Force the pool of requests to complete.
$promise->wait();
問題は、私の要求の一部であります500のHTTP応答で応答を返しますが、まだ何らかのコンテンツを送信しています(たとえば、エラーが発生した理由)。 Guzは残念なことに、500のステータスコードを持つクラスhttpレスポンスを「拒否」と呼びます。そのパラメータが拒否された関数に存在しないため、元のレスポンスを取得できないようです。
しかし、私は$reason
にアクセスできます。 xdebug
プロパティはそうのように見える文字列としてHTMLが含まれてい
{
xdebug: "..."
}
:
GuzzleHttp\Exception\ServerException: Server error: `GET http://example.com` resulted in a `500 Internal Server Error` response: {"failure_reason":"Useful message"} in [...stacktrace ...]
これは元の応答が含まれていますが、私は簡単としてそれを抽出することはできません私の場合、それはそうのようなJSONを含んでいHTMLで隠されているので、非常に役に立たない。私はまた、これが最初にどのように設定されているのか分かりません。
私の質問は、どのように拒否された同時リクエストに対する応答にアクセスできますか?