Filbert Umbawa
Filbert Umbawa

Reputation: 11

Issue with Multiple Laravel API Requests via cURL on Nginx in Laragon

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>";
}
?>


Images:

This is sample of testing concurrent request in cURL using Laravel API (Loading not stop until we stopped the NGINX in Laragon or it will be 504 (Gateway Timed-Out)

This is the result when one of my request is from Fake API

Upvotes: 1

Views: 42

Answers (0)

Related Questions