1

I use curl to request data from a server. Because I need to perform a check if the server is responding. I use this code at the moment:

    private function getAddress(){

    //...prepare connection
    try{
        $response = $client->sendCommand($command);
        return json_decode($response->getBody()->getContents());
    }
    catch(Exception $e){
        return json_encode([
            'errors' => 'server offline',
            ]);
    }

Using this code I get this error when server is offline, my catch{} block won't get executed.

Exception in CurlDriver.php line 76:
Failed to connect to IP port PORT: Connection refused

LF00
  • 27,015
  • 29
  • 156
  • 295
wichtel
  • 181
  • 1
  • 3
  • 16

0 Answers0