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!!
+2
A:
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
Alekc
2009-05-21 13:05:29
thats what im doing ,im using @fopen instead of @file_get_contents but what i want is that error should noe appear on terminal/Konsole.By using this kind of code im getting error message on the terminal when i execute it there.I want that no error msg shud appear on termianl.
developer
2009-05-21 13:11:22
"@" sign suppress error messages, probably some other line of code causing echoing of the error. You should post a snippet of your code, otherwise it can be a bit tough to give good advice.
Alekc
2009-05-21 14:37:43
$flag=0; $file = @fopen("abc.com","rb") or $flag=1; if($flag==1) { mail(.......); die(); } else { .......... } this code is generating the mail the way i want but the problem is that i am getting that error on terminal/konsole as well,which i dont want.What i want is that no error should appear on Terminal/Konsole while executing this file even if the URL is down....I hope u r understanding what im saying........
developer
2009-05-22 04:43:31
I have updated my post. Try this variation and let me know
Alekc
2009-05-22 07:22:34
there is an ini file setting called display_errors, might want to check if that is on
bumperbox
2009-05-22 07:44:57
A:
if (!$content = file_get_contents('http://example.org')) {
mail(...);
}
powtac
2009-05-21 13:06:28
+1
A:
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
}
Brent Baisley
2009-05-21 13:21:15