I have a file that opens a URL and reads it and does the parsing. Now if that URL goes dwon and my file fails to open it then what i need is that an error mail should get generated but on terminal or konsole no error message should appear. how can i do that? Plz help!!
You can always do something like this (i'm assuming you are using file_get_contents)
$file = @fopen("abc.com","rb");
if(!$file) {
@mail(.......);
die();
}
//rest of code. Else is not needed since script will die if hit if condition
if (!$content = file_get_contents('http://example.org')) {
mail(...);
}
Use curl instead if you are retrieving files over the network. It has error handling built in and it will tell you the error that occurred. Using file_get_contents won't tell you what went wrong, it also won't follow redirects.
$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
}