Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HttpClient] Add support for pausing responses #18806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

alexandre-daubois
Copy link
Member

Fix #13780

@@ -1043,6 +1043,10 @@ following methods::
// returns detailed logs about the requests and responses of the HTTP transaction
$httpLogs = $response->getInfo('debug');

// the special "pause_handler" info item is a callable that allows to delay the request
// this helps implement delayed retries or throttling streams for example
$response->getInfo('pause_handler')(2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks confusing. If I want to add e.g. a 2-second delay in the request, I would expect a delay => 2 option in the request() method.

But, modifying the response object instead of the request, and using a getter method instead of a setter looks very very counter-intuitive 😐

Maybe I'm missing something here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To give some more context, here's how others do:

wget defines these options:

wget --wait=seconds
wget --random-wait

See https://man7.org/linux/man-pages/man1/wget.1.html

curl defines several options to define rate limiting:

# limit rate in bytes per second
curl https://example.com/ --limit-rate 200K

# limit by number of requests per second, hour, etc.
curl --rate 2/s -O https://example.com/[1-100].jpg
curl --rate 3/h -O https://example.com/[1-10].jpg

See https://everything.curl.dev/usingcurl/transfers/rate-limiting

Copy link
Member Author

@alexandre-daubois alexandre-daubois Sep 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the confusion, here is the explanation from the pull request:

Returning the handler as an info item saves adding a new method and thus plays well with decorators, without requiring a new dedicated interface.

Thus, I'm not sure how to introduce this feature. Maybe this should be done in a different section? 🤔

Copy link
Member

@nicolas-grekas nicolas-grekas Sep 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pauses the response, not only the request. Pausing is how you implement throttling for example, which is about inserting many many small delays when you read the body of the response.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thanks for additional insights. Let's merge this then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants