curl status code code example
Example 1: php curl print status
$url = 'http://www.example.com';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, true); // we want headers
curl_setopt($ch, CURLOPT_NOBODY, true); // we don't need body
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT,10);
$output = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo 'HTTP code: ' . $httpcode;
Example 2: curl return code only
curl -s -o /dev/null -w "%{http_code}" http://www.example.org/
Example 3: get status code of curl
curl -o /dev/null -s -w "%{http_code}\n" http://localhost
Example 4: curl get return code
curl -I http://www.example.org