Closed ghost closed 7 years ago
Have you tried CURL debug? A nice explanation can be found here https://blog.kettle.io/debugging-curl-requests-in-php/ and that may narrow it down for you. I find that CURLOPT_SSL_VERIFYPEER is normally the biggest culprit.
Best of luck
I don't actually have a connection issue.... Things work fine. What I'm trying to do is catch the thrown exception, to output my own error message when in the rare circumstance that my system temporarily loses an internet connection. Right now I'm purposefully disabling my internet connection.
Here in this code the API throws an exception:
if (($error = curl_error($feed)) !== '')
{
curl_close($feed);
throw new \Exception($error);
}
What I'm trying to do is customize the output that the exception displays by catching it with this:
for($abc = 0; $abc <= 2; $abc++){
try{
$twitterGet = new TwitterAPIExchange($settings);
$twitterPost = new TwitterAPIExchange($settings);
}catch(Exception $e){
echo 'Exception Caught';
if($abc === 2){
exit("Failed to Connect to Twitter.");
}
}
if(!isset($e) || $e==='' || $e===null){
break;
}
}
The issue is the above is NOT catching the exception.
@AndrewMcCarrick , This is a bit outside my comfort zone but hopefully I can't lead you astray twice! You may want to look at curl_getinfo() and checking the header as this should tell give you a 404 or another timeout error... e.g. I'm not sure if this is done already in this Twitter API but I can't think of anywhere else you would check connectivity.
curl_exec($ch);
$result = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($result != 200) {
die('Request failed: HTTP status code: ' . $result);
}
I'm trying to catch an exception that is thrown during the performRequest (the if statement with the conditional: (($error = curl_error($feed)) !== '')) but can't seem to get it to function correctly. Any ideas?
Here's what I'm trying to do:
Doing the above I still get an exception coming through and giving me a Fatal Error and Exception notice when I lose an internet connection from the system running the script.