Php error handling
3 answers
Use curl instead if you are downloading files over the network. It has error handling built in, and it will report the error to you. Using file_get_contents won't tell you what went wrong, it won't follow redirects either.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://domain.com/file');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$result = curl_exec($ch);
if ( $result == false ) {
$errorInfo = curl_errno($ch).' '.curl_error($ch);
mail(...)
} else {
//Process file, $result contains file contents
}
+1
a source to share