WordPress / WordPress/Requests
blocking => false not working
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 3.6k
- Forks
- 500
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 5
Description
Summary
When I set blocking => false, the request is still blocking.
Given the following code sample
# make options
$options = array(
'timeout' => 60,
'connect_timeout' => 10,
'blocking' => false
);
# request
$response = WpOrg\Requests\Requests::request($url, $headers, $data, POST, $options);
Unfortunately, if I set a short timeout like 1 second, the remote API call will not complete.
I don't need the response, only for it to run in the background while the script does something else.
I'd expect the following behaviour
I would expect it to return immediately, so the rest of the script can run.
Instead this happened
With a long API call lasting over 1 minute, the script hangs until it returns a reply.
Additional context
The way around this for non blocking requests is to use curl with CURLOPT_NOSIGNAL set to 1.
This let's me timeout early and the api call will complete properly.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1); // Set timeout to 1 second
curl_setopt($ch, CURLOPT_NOSIGNAL, 1); // Ignore all cURL signals to ensure script continues
curl_exec($ch);
curl_close($ch);
Your environment
| Environment | Answer |
|---|---|
| Operating system and version: | Ubuntu 22.04 |
| PHP version | 8.2 lsapi, openlitespeed |
| Requests version | v2.0.7 |
Tested against develop branch?
no
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the provided Requests::request call with blocking set to false, a short timeout, and a long-running endpoint, then compare its behavior with the cURL example using CURLOPT_NOSIGNAL. Trace how the blocking and timeout options are handled in the request path. Done means the call returns promptly while preserving the intended non-blocking request behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100