Answer the question
In order to leave comments, you need to log in
What condition to put if the address is not available in curl?
Hello. There is WordPress 5.8.2. On the site, I use the curl library with the following construction
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url . '?' . http_build_query($params));
$response = curl_exec($ch);
$data = new SimpleXMLElement($response);
print_r($response);
curl_close($ch);
Answer the question
In order to leave comments, you need to log in
after calling curl_exec, make a call to curl_getinfo and check what exactly the server returns to you, in particular CURLINFO_HTTP_CODE (or better CURLINFO_RESPONSE_CODE) ($info['http_code']) should be 200, if not, then see
CURLINFO_SSL_VERIFYRESULT (see the list of codes in the comments) and CURLINFO_PROXY_SSL_VERIFYRESULT if a proxy is used,
see the response CURLINFO_HTTP_CONNECTCODE, CURLINFO_OS_ERRNO
CURLINFO_CONDITION_UNMET
ps also check $response, if it is empty then there is no point in trying to parse it into xml, this is also an error (this means the server returned an empty response without generating errors, this happens when crooked hands backend programmers implement api)
Always use the response time limit.
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); //5 секунд
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question