Reputation: 11
I'm trying to configure Nginx with PHP 7.4 NTS in Laragon and I'm encountering an issue with making (probably concurrent?) API requests.
My Setup:
Behavior:
Example Code (Two Requests via cURL):
<?php
class CurlRequest {
public function sendGetRequest($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json"]);
$response = curl_exec($ch);
if (curl_errno($ch)) {
$error = 'Curl error: ' . curl_error($ch);
curl_close($ch);
return $error;
}
curl_close($ch);
return json_decode($response, true);
}
}
// Example usage
$api = new CurlRequest();
$response1 = $api->sendGetRequest('http://localhost/crm-api/api/v1/users');
if (is_array($response1)) {
echo "<pre>Users API Response:\n";
print_r($response1);
echo "</pre>";
} else {
echo "<pre>Error fetching Users API: $response1</pre>";
}
$response2 = $api->sendGetRequest('http://localhost/crm-api/api/v1/products');
if (is_array($response2)) {
echo "<pre>Products API Response:\n";
print_r($response2);
echo "</pre>";
} else {
echo "<pre>Error fetching Products API: $response2</pre>";
}
?>
Problem: When I send two Laravel API requests at once via cURL, the second request doesn't seem to get processed and just hangs or times out. However, if I send requests separately (one after another), both work fine. Similarly, if I mix a real Laravel API request with a fake one, they work fine concurrently.
What I've Tried: Tested with Postman and it works fine for both single and multiple requests.
One request at a time works fine via cURL.
Using Fake APIs concurrently also works, indicating the issue is specific to Laravel API calls.
Questions:
Images:
This is the result when one of my request is from Fake API
Upvotes: 1
Views: 42