menu

arrow_back How to check the availability of third party resource?

by
1 vote
Hello.
There is a script. The script accesses a third-party resource via CURL. If a third-party resource falls or long handles the request, then the script, trying to wait for a response, either crashes or "hangs".
There is an option to use CURLOPT_TIMEOUT or CURLOPT_TIMEOUT_MS. But I don't see any reason to send data to someone else's server if it is unavailable, and if available the response time it will be obviously more time the life of the script.
Is there a way to "pinganut" third-party resource with php?

1 Answer

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