Search code examples
phpcurlfailover

php curl fail-over function for "couldn't connect to host"


I have a php curl script which crawls different websites . The problem is that after a while I think the websites place a kind of temporary ban on my IP and the script is unable to connect to the host anymore(as I'm getting "couldn't connect to host" error) . I would like to set a condition/function to make the script stop for a while (e.g sleep(30)) but I don't know how to detect(handle the error) when cURL is unable to connect to the host.


Solution

  • php.net/curl_errno