Repository navigation
Conversation
Introduce `WP_Http::request_multiple()`, `wp_remote_request_multiple()` and `wp_safe_remote_request_multiple()`, which send a batch of requests side by side and return their responses keyed and ordered like the requests. `WP_Http::request()` is split into `prepare_request()` and `finalize_response()`, so a batched request goes through the same steps as a single one: the `http_request_args`, `pre_http_request` and `http_response` filters, URL validation, blocked hosts, proxies and the `http_api_debug` action all apply to each request individually. Compared to the earlier patch on the ticket: * The single-request functions keep their signatures instead of accepting an array of requests, so `reject_unsafe_urls` can still be passed for a batch. * Batches are sent at most `concurrency` requests at a time (default 6, filterable with `http_request_multiple_concurrency`). * The `http_api_curl` action fires for batched requests too. Requests dispatches `curl.before_multi_add` instead of `curl.before_send` for them, which `WP_HTTP_Requests_Hooks` did not map. * When the Requests library rejects a batch as a whole, its requests are retried one by one so that each gets its own response or error. See #37459. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RvSBA4zz2vHphxunmJCV2G
* Catch `Exception` around `Requests::request_multiple()`. The Requests library only documents `InvalidArgument` on that method, although the URL validation and transport lookup it performs throw `WpOrg\Requests\Exception`, so PHPStan considered the narrower catch dead. * Document the two shapes `WP_Http::prepare_request()` returns with a `@phpstan-return`, as hash notation cannot express a union of shapes. * Describe the `$requests` parameter in prose. Its hash notation described a single request rather than the list of them. See #37459. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RvSBA4zz2vHphxunmJCV2G
`WP_Http::prepare_request()` signals a short-circuited request with the presence of the `response` key, but the callers checked it with `isset()`, which does not see a `null` value. A `pre_http_request` callback returning `null` therefore made `WP_Http::request()` read undefined keys and `WP_Http::request_multiple()` send a request without a URL, whereas `null` used to be returned to the caller unchanged. Check for the key with `array_key_exists()` instead, and add a test for it. See #37459. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D8CZQKtzf87KYDehmhKnED
…e `http_api_curl` docblock. See #37459. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D8CZQKtzf87KYDehmhKnED
* Declare the response array as a `Response` type on `WP_Http` and use it for the return value of `request()`, `finalize_response()` and the short-circuit value `prepare_request()` returns, rather than describing the shape in each place.
* Declare the prepared request as a `Prepared_Request` type and give `request_multiple()`, `wp_remote_request_multiple()` and `wp_safe_remote_request_multiple()` value types for their requests, options and responses.
* Type the results the Requests library returns for a batch.
* Only parse request arguments given as a string, since arrays are passed on as they are.
* Align the parameter descriptions of `finalize_response()` and reference methods with `{@see}`.
See #37459.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D8CZQKtzf87KYDehmhKnED
…ultiple()`. Introduces `download_url_multiple()` to download multiple URLs concurrently using `wp_safe_remote_request_multiple()`. Refactors `download_url()` to share response handling with `_wp_handle_download_response()`, ensuring consistent MIME type detection, Content-Disposition extraction, checksum verification, and signature checking. Updates `Plugin_Upgrader::bulk_upgrade()` and `Theme_Upgrader::bulk_upgrade()` to pre-download compatible packages in parallel before iterating through the installation loop, significantly reducing bulk update wall-clock time and preventing timeouts on shared hosting. Includes dedicated unit tests in `downloadUrlMultiple.php` and integration tests in `bulkUpgrader.php`. See #37459.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Trac ticket: https://core.trac.wordpress.org/ticket/37459
Building on @swissspidy's
wp_safe_remote_request_multiple()in PR #13657, I have implementeddownload_url_multiple()and wired it intoPlugin_Upgrader::bulk_upgrade()andTheme_Upgrader::bulk_upgrade().Benchmark Results (5 Real WP.org Packages)
Tested downloading 5 real production plugins (
hello-dolly,wp-multibyte-patch,classic-widgets,regenerate-thumbnails,duplicate-post):download_url): 6.315sdownload_url_multiple): 2.147sImplementation Summary
download_url_multiple()added tosrc/wp-admin/includes/file.phpwith concurrent streaming._wp_handle_download_response()helper, removing code duplication between single and multiple downloads (shares Content-Disposition, MIME checks, MD5 verification, and .sig checks).Plugin_Upgrader&Theme_Upgraderpre-fetch compatible packages in parallel before the update loop; unconsumed files are cleaned up safely.downloadUrlMultiple.php(7 tests, 33 assertions) and integration tests inbulkUpgrader.php(3 tests, 14 assertions). 100% passing; 0 PHPCS warnings/errors.Branch:
feature/bulk-upgrader-concurrent-downloadsFull details and implementation notes: See attached PR description.