Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mooseh's avatar

Guzzle Caching responses?

Hi Everyone, Im just in the process of testing laravel, and to test its capabilities, I have written a Guzzle Function this is called in a loop and this searched 1080 sensors for a curl response, and then displays the response, the only thing it running this kind of command is pretty hefty, so i was curious as to how i cache the Guzzle responses for a a certain time?

here's my code

public function streamData()
        {
        
        $streamNames = $this->streams()->pluck('mount_name');

        $streamNames = substr($streamNames,1,-1);

        $streamNames = str_replace('"', "", $streamNames);

        $streamNames = str_replace(' ', "", $streamNames);

        $url = 'http://myApi.com/api.php?mount=' . $streamNames . '&type=connected';
        
        $client = new GuzzleHttpClient();
        
        $apiRequest = $client->request('GET', $url);

        $content = json_decode($apiRequest->getBody()->getContents());

        return $content[0]; // process the response however makes sense
        }

}
0 likes
2 replies
mooseh's avatar

Yeh I was looking at that i think it might actually be built into guzzle but im not sure how to use it :D

Please or to participate in this conversation.