Why is file_get_contents can get remote data while PHP Curl gives blank page?

255 views Asked by At

I am trying to download remote XML feed using PHP Curl , But PHP curl is giving me blank page while php function file_get_contents can get the contents.

i am trying to make php curl work as its faster than file_get_contents and can set multiple extra options.,

i am doing request curl like this.

$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_VERBOSE,true);
$data = curl_exec($ch);
curl_close ($ch);

and when i do echo $data; all i get is blank page.

but if i use file_get_contents instead , then i can get whole XML feed, why is that ?

i have tried setting

curl_setopt($ch, CURLOPT_HEADER, 1);

still it shows blank page.

i even tried

error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('max_execution_time', 300); //300 seconds = 5 minutes

but when i use curl i get blank page.

i am using

Windows Version: Windows XP SP3 32-bit
XAMPP Version: 1.8.2
# php -v
PHP 5.4.31 (cli) (built: Jul 23 2014 20:20:15)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies

How can i make the PHP Curl give me data instead of blank page. ?

0

There are 0 answers