Skip to content

Feature/bulk upgrader concurrent downloads - #14081

Open
robelsust wants to merge 9 commits into
WordPress:trunkfrom
robelsust:feature/bulk-upgrader-concurrent-downloads
Open

robelsust wants to merge 9 commits into
WordPress:trunkfrom
robelsust:feature/bulk-upgrader-concurrent-downloads

Conversation

@robelsust

@robelsust robelsust commented Oct 7, 2026 •

Copy link
Copy Markdown

Trac ticket: https://core.trac.wordpress.org/ticket/37459

Building on @swissspidy's wp_safe_remote_request_multiple() in PR #13657, I have implemented download_url_multiple() and wired it into Plugin_Upgrader::bulk_upgrade() and Theme_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):

  • Sequential (download_url): 6.315s
  • Concurrent (download_url_multiple): 2.147s
  • Speedup: 2.94x faster (66% latency reduction)

Implementation Summary

  1. download_url_multiple() added to src/wp-admin/includes/file.php with concurrent streaming.
  2. Extracted private _wp_handle_download_response() helper, removing code duplication between single and multiple downloads (shares Content-Disposition, MIME checks, MD5 verification, and .sig checks).
  3. Plugin_Upgrader & Theme_Upgrader pre-fetch compatible packages in parallel before the update loop; unconsumed files are cleaned up safely.
  4. Resilience: Automatic fallback to package URL if any single batch item fails.
  5. Full Tests: Added dedicated unit tests in downloadUrlMultiple.php (7 tests, 33 assertions) and integration tests in bulkUpgrader.php (3 tests, 14 assertions). 100% passing; 0 PHPCS warnings/errors.

Branch: feature/bulk-upgrader-concurrent-downloads
Full details and implementation notes: See attached PR description.

swissspidy and others added 9 commits September 22, 2026 12:14
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.
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props swissspidy, therssoftware.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants