Opened 10 years ago
Closed 10 years ago
#27021 closed enhancement (fixed)
Add more context to the http_api_curl action
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 3.9 | Priority: | normal |
Severity: | normal | Version: | |
Component: | HTTP API | Keywords: | has-patch |
Focuses: | Cc: |
Description
Currently the http_api_curl action just passes the cURL handle, which is not very useful without more context, like what URL was requested and what the arguments were.
A simple use case is CURLOPT_TIMEOUT_MS
which was removed in r12472 due to bugginess with some versions of PHP and cURL, but which works pretty well on newer versions, so with a more useful action, it could easily be implemented in a plugin:
function better_curl_timeout( $handle, $r ) { if ( defined( 'CURLOPT_CONNECTTIMEOUT_MS' ) && defined( 'CURLOPT_TIMEOUT_MS' ) ) { $timeout_ms = (int) ceil( 1000 * $r['timeout'] ); curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT_MS, $timeout_ms ); curl_setopt( $handle, CURLOPT_TIMEOUT_MS, $timeout_ms ); } } add_action( 'http_api_curl', 'better_curl_timeout', 10, 2 );
Attachments (2)
Change History (9)
#2
@
10 years ago
- Milestone changed from Awaiting Review to 3.9
As much as we shouldn't be encouraging people to use transport-specific hooks such as this, if we're going to have the hook in there, we might as well make it pass context.. so seems like a decent suggestion to me.
#3
follow-ups:
↓ 4
↓ 5
@
10 years ago
Doesn't moving from do_action_ref_array() to do_action() cause issues with functions anticipating the by-reference variable?
#4
in reply to:
↑ 3
@
10 years ago
Replying to nacin: You're right, though $handle
is just a resource so not sure there's a point to pass it by reference. Unless the hooked action to replaces the resource with a brand new one using curl_init()
, so yeah maybe do &$handle
instead.
#6
@
10 years ago
Yes, makes sense. Refreshed in 27021.2.diff, back to _ref_array() + added some docs.
Patch in 27021.diff