Author |
Message |
Dawg
RavenNuke(tm) Development Team

Joined: Nov 07, 2003
Posts: 928
|
Posted:
Fri Nov 10, 2006 4:06 pm |
|
I have a nifty little radar block that works real good. The problem with it is...if anything goes wrong....ie:it can not find it's file or what ever....it poops the entire site.
How do I amke it "Die Nice"?
I would like to feed it another image if anything goes wrong.
Dawg
Code:<?php
if (eregi("block-Radar_Front.php",$PHP_SELF)) {
Header("Location: index.php");
die();
}
$q = 3600; //cache time delay in seconds, 3600=one minute
$filesize = filesize("cache/latest_radar.png");
$lastvisit = filemtime("cache/latest_radar.png");
$currenttime = getdate(time());
$currentdate = $currenttime["0"];
$difference = $currentdate - $lastvisit;
$diff = $q-$difference;
$hrs = intval($diff/3600);
$min = intval(($diff-($hrs*3600))/60);
$content .= "<table border=\"1\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bgcolor=\"#000000\" bordercolor=\"#111111\" width=\"447\" height=\"398\">";
$content .= "<tr><td align=\"center\"><a href=\"http://mysite.com/modules.php?name=Radar&mode=2&animated=1&track=1&advisories=0\" target=\"_blank\"><img src=\"cache/latest_radar.png\"
width=\"447\" height=\"398\" alt=\"Click Image\"></tr></td></table>";
$content .= "<table border=\"1\" align=\"center\" bgcolor=\"#fffff0\" width=\"150\" height=\"20\">";
$content .= " <tr><td align=\"center\"><a href=\"http://mysite.com/modules.php?name=Radar&mode=2&animated=1&track=1&advisories=0\" target=\"_blank\">NEW
Local Loop</a> ";
$content .= " <tr><td align=\"center\">Next Image Update<br>$hrs hrs $min mins ";
$content .= "</tr></table>";
if ( ($difference < $q) AND ($filesize != 0) )
{ }
elseif ( ($difference > $q) OR ($filesize == 0) )
{
$fc = fopen("cache/latest_radar.png", "wb");
$file = fopen ("http://www.srh.weather.gov/ridge/lite/N0R/LTX_0.png", "rb");
if (!$file) {
$info = "E";
exit;
}
else
{
while (!feof ($file)) {
$line = fread ($file, 4096);
fwrite($fc,$line);
}
}
fclose($fc);
fclose($file);
$info = "F"; }
?>
|
|
|
|
|
 |
evaders99
Former Moderator in Good Standing

Joined: Apr 30, 2004
Posts: 3221
|
Posted:
Fri Nov 10, 2006 11:30 pm |
|
well you could surpress errors from fopen using the @ symbol
You could also try catching the error and passing it to an error handling code
I haven't used this, but it looks like it should work
http://us2.php.net/errorfunc |
_________________ - Only registered users can see links on this board! Get registered or login! -
Need help? Only registered users can see links on this board! Get registered or login! |
|
|
 |
gregexp
The Mouse Is Extension Of Arm

Joined: Feb 21, 2006
Posts: 1497
Location: In front of a screen....HELP! lol
|
Posted:
Sat Nov 11, 2006 12:40 am |
|
die nice could possible be done by return;
Side note Ive read but not really had time to determine its functionality.
Another approach would be, to take your wording, if something goes wrong.
In other words create an if statement and put your content within that, it will not die but if it fails, it would load something else instead. |
_________________ For those who stand shall NEVER fall and those who fall shall RISE once more!! |
|
 |
 |
hitwalker
Sells PC To Pay For Divorce

Joined:
Posts: 5661
|
Posted:
Sun Nov 12, 2006 6:17 am |
|
yeah but the image she wants has to be loaded within a specific time before php automaticaly drops it..
things ive read about this were solving it with a time_out,but thats never gonna work to if your on safe_mode.
If statement is nice but we have to tell it first what to do... |
|
|
|
 |
Dawg

|
Posted:
Sun Nov 12, 2006 4:57 pm |
|
LOL....Hitwalker...She is a Big 270lb HE. LOL!
Here is the deal....The block is supposed to check if a file exists....if it does exist, it checks how old the file is, if the file is more than 1 hour old it goes to the source and redownloads the new version of the file.
IF something goes wrong....then I would want to load .....File_Not_Found.gif
My guess is that I want to put the $content in an IF statement.
What I do not know is what I look for if something goes wrong. In other words...what do I look for IF something goes wrong.
You should be able to use this block right out of the box by creating a dir called cache...giving it permissions and then run the file. It should work.
I put this together out of other parts and pieces a while back.
Dave |
|
|
|
 |
hitwalker

|
Posted:
Sun Nov 12, 2006 4:59 pm |
|
She is a Big 270lb HE ?
Did i miss anything? |
|
|
|
 |
Dawg

|
Posted:
Sun Nov 12, 2006 5:06 pm |
|
[quote="hitwalker"]yeah but the image she wants has to be loaded within a specific time .......[quote] |
|
|
|
 |
hitwalker

|
Posted:
Sun Nov 12, 2006 5:11 pm |
|
and this is just theoretical....
Code:
$timeout = 3;
f ( ($difference < $q) AND ($filesize != 0) )
{ }
elseif ( ($difference > $q) OR ($filesize == 0) )
{
$old = ini_set('default_socket_timeout', $timeout);
$fc = fopen("cache/latest_radar.png", "wb");
$file = fopen ("http://www.srh.weather.gov/ridge/lite/N0R/LTX_0.png", "rb");
ini_set('default_socket_timeout', $old);
stream_set_timeout($file, $timeout);
stream_set_blocking($file, 0);
if (!$file) {
$info = "E";
exit;
}
else
{
while (!feof ($file)) {
$line = fread ($file, 4096);
fwrite($fc,$line);
}
}
fclose($fc);
fclose($file);
$info = "F"; }
That should time out after a given time..
|
|
|
|
|
 |
|