I am trying to go through a basic curl example. I have a php file running on a server that seems to have curl properly installed and I have another empty text document on the server that I am trying to have information copied to. When I run the script by opening the php file, no information is written to the text file.
For the server, it says curl is enabled:
curl
cURL support enabled
cURL Information libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
Here is the php file I am trying to run:
http://www.php.net/manual/en/curl.examples-basic.php
<?php
$ch = curl_init("http://www.example.com/");
$fp = fopen("example_homepage.txt", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
?>
I have an empty file named “example_homepage.txt” in the same folder. Any idea what is going wrong?
Your script is working perfectly. A quick test with
curl example.comshows that it returns no output. If you want to actually fetch content, try a real site like$ch = curl_init("http://www.google.com/");.The address “www.example.com” is just that, an example. You’re meant to replace it with something real.