Jump to content

[SOLVED] More control over time() needed or something else to slow this down?


djfox

Recommended Posts

In a previous post, it was told to me to use time() for a function I`m working on. First, I`ll share the code:

 

<?php
$time= time();

if ($time=time()+3600) {  

$petfood= $rows[5] -2;
   mysql_query("UPDATE ownedpets SET food=$petfood WHERE id='$id'");
}
?>

 

What this is supposed to do is subtract 2 from $rows[5] every hour. But instead what is happening is that 2 is subtracted from $rows[5] every time the page loads. Changing the time (right now it`s 3600) doesn`t affect it at all. Am I doing something wrong?

To run a script every hour, you need to set up a cron job. You can completely take all that time() stuff out of your script.

 

<?php

$petfood= $rows[5] -2;
mysql_query("UPDATE ownedpets SET food=$petfood WHERE id='$id'");

?>

 

You set them up with your host. Usually you can set them up from the control panel, it all depends on what host you use. Some hosts don't even offer cron jobs, so check that first.

Why do you need to update your database every hour? Are you feeding as pet?

 

Yes, it`s for the virtual pet system I`m developing for my site. The hunger meter of all the pets need to go down by a time interval, to encourage the owners to feed the pet.

So why not force the time to be updated when the owner opens their account?

 

Instead of push use pull to save on resources...

 

Think about 100,000 owners, your script will run infinetly with push - cron job..

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.