Saurabh
Saurabh

Reputation: 1065

Curl stopped working all of a sudden

I was working on a project for which i was using curl to fetch some data from a website (more so like a API call). Two nights ago I checked everything and it was working smoothly but all of a sudden yesterday morning I started getting an error:

A PHP Error was encountered

Severity: Warning

Message: DOMDocument::loadXML() [domdocument.loadxml]: Empty string supplied as input

Filename: controllers/user.php

My code is:

$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data=curl_exec($ch);
curl_close($ch);
$doc = new DOMDocument();
$doc->loadXML($data);
$doc->save("test2.xml");

The url is correct as the everything was working 2 days ago!

I am working on wamp server currently and php_curl is enabled!

This is the API i am trying to call! Is there any other method to send the request and fetch the data apart from curl?

Upvotes: 0

Views: 4785

Answers (1)

Sabeen Malik
Sabeen Malik

Reputation: 10880

As an alternate try echo file_get_contents($url);

Also see what you get if you do something like this:

$data=curl_exec($ch);
echo curl_error($ch);
echo "<br>";
$info = curl_getinfo($ch);
print_r($info);
curl_close($ch);

The curl info and curl error might give you some insight about the request.

Upvotes: 1

Related Questions