Catching 502 error using file()
Posted: Fri Mar 06, 2009 3:25 pm
Hello
I use file() in a script to read a remote webpage, but sometimes this remote site has problems and can cause a "502 bad gateway" error and so the rest of the script wont complete properly because the info wasnt loaded.
What would be the best way to deal with this error? I mean, retry loading the page if it fails? PHP does the whole on screen "
I use file() in a script to read a remote webpage, but sometimes this remote site has problems and can cause a "502 bad gateway" error and so the rest of the script wont complete properly because the info wasnt loaded.
What would be the best way to deal with this error? I mean, retry loading the page if it fails? PHP does the whole on screen "
Code: Select all
cant do this..." error stuff when the 502 error happens, so its not like the error slips through.
I know theres the try...catch method, but would this catch the 502 error?
Could i maybe do something like:
[syntax=php]$worked = 0;
while($worked == 0){
try{
file("...");
if it worked set $worked = 1
}catch(exception...){
}
}
[/syntax]
Any input is appreciated :)