WordPress / WordPress/Requests

kind of async support

Open
#53 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Extras Type: enhancement
Dominant language
PHP
Stars
3.6k
Forks
500
Avg merge
2d 21h
Merged PRs (30d)
5

Description

I would like to propose an additional async like approach for Request. The client API would look something like this:


// trigger the requests
$future = Requests::request_async($requests, $options);

// do whatever PHP stuff you like
echo "lala";

// ...
// after you have done everything which is not related to the asyncRequest

 // wait for all curl requests which are not finished yet and 
// returns their results as request_multiple would do.
// also frees all remaining resources
$results = $future->getResult();

// process your result

to implement this kind of handling I would like to split Requests_Transport_cURL::request_multiple() in two smaller parts.

The first request_async part would start the requests (curl_init, curl_setopt, curl_multi_init, curl_multi_add_handle and kick of the requests using curl_multi_exec).

The second part $future->getResult() will run the loop over curl_multi_exec until everything is finished, cleanup using curl_multi_remove_handle & curl_multi_close.

this kind of request handling is AFAIK only possible using curl, therefore the default implementation would do the stuff synchrously (call request_mulitple).

I am willing to provide the implementation in case you give your 👍.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading Requests_Transport_cURL::request_multiple() and the Requests::request_async() API described in the issue. Define how the future object starts and completes curl work, releases remaining handles, and returns the same results as request_multiple(); verify that non-cURL transports retain synchronous behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.