Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3cb560b

Browse files
[HttpClient] doc how to cancel a request
1 parente0a86d1 commit3cb560b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

‎components/http_client.rst‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,29 @@ response sequentially instead of waiting for the entire response::
303303
fwrite($fileHandler, $chunk->getContent());
304304
}
305305

306+
Canceling Responses
307+
~~~~~~~~~~~~~~~~~~~
308+
309+
To abort a request (e.g. because it didn't answer in due time, or you want to
310+
fetch only the first bytes of the response, etc.), you can either:
311+
312+
* use the ``cancel()`` method of ``ResponseInterface``::
313+
314+
$response->cancel()
315+
316+
* throw an exception from a progress callback::
317+
318+
$response = $client->request('GET', 'https://..;', [
319+
'on_progress' => function (int $dlNow, int $dlSize, array $info): void {
320+
// ...
321+
322+
throw new \MyException();
323+
},
324+
]);
325+
326+
The exception will be wrapped in a ``TransportExceptionInterface`` and will
327+
abort the request.
328+
306329
Handling Exceptions
307330
~~~~~~~~~~~~~~~~~~~
308331

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp