Test if cURL is working Print

  • 39

Create a file called test-curl.php which includes the below script.
 
 
<?php
$ch = curl_init("http://www.google.com/");
$fp = fopen("google_homepage.txt", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
?>
 
 
After you execute or load this page the script will create a google_homepage.txt within the same directory that includes the source of the Google homepage. If you see the text file populated with the html source code of google.com, cURL is working.

Was this answer helpful?

« Back