Created
March 8, 2013 15:11
-
-
Save iwek/5117081 to your computer and use it in GitHub Desktop.
PHP Curl Example with Error Checking
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//initialize | |
$ch = curl_init(); | |
// 2. set the options, including the url | |
curl_setopt($ch, CURLOPT_URL, "https://api.pingdom.com/api/2.0/traceroute?host=techslides.com"); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array("App-Key: YOUR-KEY-HERE")); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
//execute | |
$output = curl_exec($ch); | |
if ($output === FALSE) { | |
echo "cURL Error: " . curl_error($ch); | |
} else { | |
var_dump($output); | |
} | |
//free up the curl handle | |
curl_close($ch); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will not work, here is the correct version for Pingdom API.