D
D
Dark_Dante2015-07-01 09:24:06
PHP
Dark_Dante, 2015-07-01 09:24:06

How to check the availability of a third-party resource?

Hello.
There is a script. The script accesses a third-party resource via CURL. If a third-party resource crashes or processes a request for a long time, then our script, trying to wait for a response, either crashes or "hangs", respectively.
There is an option to use CURLOPT_TIMEOUT or CURLOPT_TIMEOUT_MS. But I see no reason to send data to someone else's server if it is not available, and if it is available, then its response time will obviously be longer than the lifetime of our script.
Is it possible to somehow "ping" a third-party resource using php?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Fateev, 2015-07-01
@Dark_Dante

function ping($host,$port=80,$timeout=6)
{
        $fsock = fsockopen($host, $port, $errno, $errstr, $timeout);
        if ( ! $fsock )
        {
                return FALSE;
        }
        else
        {
                return TRUE;
        }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question