About the problem of obtaining web page data remotely by CURL in PHP.

on the problem of CURL remotely fetching web page data in PHP.
needs to grab the contents of the dictionary, and the local test can return FALSE when placed on the server.

I saw that some related questions were raised before https://codeshelper.com/q/10.
, but with the addition of CURLOPT_USERAGENT, it is still ineffective. Please take a look at it

.
<?php
function curl_get_contents($url, $timeout = 15) { 

    // dump($url);
    $curlHandle = curl_init(); 
    curl_setopt( $curlHandle , CURLOPT_URL, $url ); 
    curl_setopt( $curlHandle , CURLOPT_RETURNTRANSFER, 1 ); 
    curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, FALSE); // https hosts
    curl_setopt($curlHandle, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($curlHandle,CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)");
    curl_setopt( $curlHandle , CURLOPT_TIMEOUT, $timeout ); 
    // dump(curl_error($curlHandle));

    // dump($curlHandle);
    $result = curl_exec( $curlHandle ); 
    curl_close( $curlHandle ); 
    return $result; 
} 


$url = "https://www.ldoceonline.com/dictionary/january";


    $html = curl_get_contents($url, 60);

    var_dump($html);

?>
Mar.10,2021

I read the request you wrote. There is nothing wrong with it. You replace USERAGENT with Mozilla/5.0 (Macintosh; Intel Mac OS X 1013. 3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36

should be an internal restriction of the website. Curl requests normally simulate the headers and parameters of pc access, and most of the time there is no problem.


is it because the server environment does not support access to the public network? since FALSE, is returned, it should be a failure to execute the curl_exec function. First, use the curl_errno function to check what the error code is. Only in this way can it be convenient to locate the problem


Thank you for the invitation. First of all, I see the existence of annotated dump, indicating that you once wanted to break the point to print information, I personally prefer to use the error_log function to print debug information in the file, and then use tail-f to monitor the output. In this way, the execution of the program is not interrupted, and the effect is more real-time.
then, for your question, there is really little information. It is recommended that you print out the curl_getinfo information to see


do you have a crul extension installed on your server?


after querying the problem of SSL and comparing it with phpinfo, it is found that the available server curl is openssl and the unavailable curl is nss. The default service installs nss.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e45462-4c228.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e45462-4c228.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?