1

In a component, I'm using the call to retrieve an xml file hosted on a website . However, in some cases, the firewall blocks this kind of request so there is no answer. In this case, how can I check for a timeout? This is my code:

$url = 'https://mysite.org/filetoretrieve.xml';

$options = new Joomla\Registry\Registry;

try
{
    $transport = new Joomla\CMS\Http\Transport\StreamTransport($options);
}
catch (Exception $e) 
{
    $this->app->enqueueMessage($e->getMessage(), 'error');

    return false;
}

if (!$transport->isSupported())
{
    return false;
}

// Create a 'stream' transport.
$http = new Joomla\CMS\Http\Http($options, $transport);

try
{
    $response = $http->get($url);
}
catch (Exception $e)
{
    $this->app->enqueueMessage($e->getMessage(), 'error');

    return false;
}

if ($response->code == '200')
{
    // Handling the answer here
}
1
0

I don't think there's a way to check specifically for a timeout. Timeout acts as a connection failure and results in an exception being thrown when calling $http->get($url). Which you are already catching.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.