Opened 12 years ago
Closed 12 years ago
#27021 closed enhancement (fixed)
Add more context to the http_api_curl action
| Reported by: | kovshenin | Owned by: | nacin |
|---|---|---|---|
| Priority: | normal | Milestone: | 3.9 |
| Component: | HTTP API | Version: | |
| Severity: | normal | Keywords: | has-patch |
| Cc: | Focuses: |
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
@
12 years ago
- Milestone Awaiting Review → 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
@
12 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
@
12 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
@
12 years ago
Yes, makes sense. Refreshed in 27021.2.diff, back to _ref_array() + added some docs.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Patch in 27021.diff