Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks
Author Message
Dawg
RavenNuke(tm) Development Team



Joined: Nov 07, 2003
Posts: 928

PostPosted: Fri Nov 10, 2006 4:06 pm Reply with quote

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"; }


?>
 
View user's profile Send private message
evaders99
Former Moderator in Good Standing



Joined: Apr 30, 2004
Posts: 3221

PostPosted: Fri Nov 10, 2006 11:30 pm Reply with quote

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 [ Only registered users can see links on this board! Get registered or login! ]

_________________
- Star Wars Rebellion Network -

Need help? Nuke Patched Core, Coding Services, Webmaster Services 
View user's profile Send private message Visit poster's website
gregexp
The Mouse Is Extension Of Arm



Joined: Feb 21, 2006
Posts: 1497
Location: In front of a screen....HELP! lol

PostPosted: Sat Nov 11, 2006 12:40 am Reply with quote

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!! 
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number
hitwalker
Sells PC To Pay For Divorce



Joined:
Posts: 5661

PostPosted: Sun Nov 12, 2006 6:17 am Reply with quote

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...
 
View user's profile Send private message
Dawg







PostPosted: Sun Nov 12, 2006 4:57 pm Reply with quote

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







PostPosted: Sun Nov 12, 2006 4:59 pm Reply with quote

She is a Big 270lb HE ?
Did i miss anything?
 
Dawg







PostPosted: Sun Nov 12, 2006 5:06 pm Reply with quote

[quote="hitwalker"]yeah but the image she wants has to be loaded within a specific time .......[quote]
 
hitwalker







PostPosted: Sun Nov 12, 2006 5:11 pm Reply with quote

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..
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©