I have this test code:
<?php
$html_brand = "https://google.com";
$ch = curl_init();
$options = array(
CURLOPT_URL => $html_brand,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_ENCODING => "",
CURLOPT_AUTOREFERER => true,
CURLOPT_CONNECTTIMEOUT => 120,
CURLOPT_TIMEOUT => 120,
CURLOPT_MAXREDIRS => 10,
);
curl_setopt_array( $ch, $options );
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ( $httpCode != 200 ){
echo "Return code is {$httpCode} \n"
.curl_error($ch);
print_r(curl_getinfo($ch));
} else {
echo "<pre>".htmlspecialchars($response)."</pre>";
}
curl_close($ch);
And page result (I have put \n before variable name for better readability) is:
Return code is 0 Array (
[url] => https://google.com
[content_type] =>
[http_code] => 0
[header_size] => 0
[request_size] => 0
[filetime] => 0
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0
[namelookup_time] => 0
[connect_time] => 0
[pretransfer_time] => 0
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => -1
[starttransfer_time] => 0
[redirect_time] => 0
[redirect_url] =>
[primary_ip] =>
[certinfo] => Array ( )
[primary_port] => 0
[local_ip] =>
[local_port] => 0 )
What is wrong here? I could not figure out why curl is not working on my machine. Internet is working, command line curl is working very fine.
I'm on PHP Version 5.5.9-1ubuntu4.14,
and this is curl section from phpinfo()
var_dump(curl_error($ch));?ping google.comfrom your server's console. Check out this question stackoverflow.com/questions/10227879/…