Auto Updating

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

Auto Updating

Post by cheatboy00 »

Ok I've been working on this game for the past... well its been 8 months now.. its just me. and I'm starting work on the actual update page... but I can do that... what I'm having troubles with, is when do i update the site.

I have this script i'm working on, and it surpose to run the update.php file every 12 hours... now i have a time in the databse from which to go off of. but i cant seem to get anything to work.. i'm totally stumped..

what i need to do is compare the current time, with the time in the database.. if the current time is greater than the time in the database than run the update script... then set the new time equaling 12 more hours than the last time in the database...

but also have to take in the factor is someone hasnt visited the site in more than a day .. therefore more than 24 hours.. so i have to check how many times i have to run it as well.. then the new time has to be the number of times i ran the script * 12 (hours), and add that to the old time to get the new time...

does anyone get what i'm talking about... anyway heres the crappy code that I produced (and doesnt work)

Code: Select all

$run = 0; // leave it at zero.. its how many times it should update
$updatetime = 12; // how often hourly.. so ever 12 hours it should update
// grabbing the time from the db ("z-H:i")
// note theres only 1 feild and 1 column in the database, and the columns called time
$up = mysql_fetch_array(mysql_query("SELECT * FROM dbz_update"));
$up2 = $upї0];
$da = explode("-", $up2);
$upday = $daї0];
$h = explode(":", $daї1]);
$uphour = $hї0];

$timezone = date("O"); // same time zone
if ($timezone == "-0500"){
   $day = date("z"); // getting their time
   $hour = date("H");
   // if the hour is greater than the db hour
   if ($hour > $uphour) {
      // if its actually the next day or more 
      if ($day > $upday){
         $diffhour = ($day - $upday) * 24;
         $run = floor(@(($diffhour-$hour) / $updatetime));
         
         // if its not the next day
      } else {
         $run = floor(@(($uphour-$hour) / $updatetime));
      }
      
      // if the hour is less than(it must be the next day) the db hour.
   } else {
      if ($day > $upday){
         $diffhour = ($day - $upday) * 24;
         $run = floor(@(($diffhour-$hour) / $updatetime));
      }
   }
   
   // not in my time zone... so have to adjust 
} else {
   // find the diffrerence in the time zones
   $newtimez = ($timezone - (-0500));
   $day = date("z"); // getting their time
   $hour = (date("H") - $newtimezone);
   if ($hour > 24) {
      $day++;
      $hour -= 24;
   } 
   
   // after that set the $day and $hour to my time zone(-0500)
   // and the rest should fall in place
   
   // if the hour is greater than the db hour
   if ($hour > $uphour) {
      // if its actually the next day or more 
      if ($day > $upday){
         $diffhour = ($day - $upday) * 24;
         $run = floor(@(($diffhour-$hour) / $updatetime));
         
         // if its not the next day
      } else {
         $run = floor(@(($uphour-$hour) / $updatetime));
      }
      
      // if the hour is less than(it must be the next day) the db hour.
   } else {
      if ($day > $upday){
         $diffhour = ($day - $upday) * 24;
         $run = floor(@(($diffhour-$hour) / $updatetime));
      }
   } 
}

// now set new date to update
that looks horrible.. if anyone can help me I'm desprite... thanks
evilcoder
Forum Contributor
Posts: 345
Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia

Post by evilcoder »

use cronjobs to execute the script.
User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

Post by cheatboy00 »

That'd be sweet and all... but ya know what.. my host doesnt support that...
evilcoder
Forum Contributor
Posts: 345
Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia

Post by evilcoder »

lol..... d'oh.. then your gonna have some problems aren't ya? The only way i know is through CRON, so sorry i cant help ya.
User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

Post by cheatboy00 »

ARG...
User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

Post by cheatboy00 »

bump!!..

dont hurt me... I just want some help :( :cry:
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

if the script can be requested via webserver you might set up somewhere else a cronjob that pulls that page/executes the script (e.g. via lynx -dump http://url.of/script)
User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

Post by cheatboy00 »

ok...........?

well what it does it updates a database.. and your not allowed remote connection as well.
Post Reply