djfox Posted October 21, 2007 Share Posted October 21, 2007 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? Link to comment https://forums.phpfreaks.com/topic/74146-solved-more-control-over-time-needed-or-something-else-to-slow-this-down/ Share on other sites More sharing options...
pocobueno1388 Posted October 21, 2007 Share Posted October 21, 2007 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'"); ?> Link to comment https://forums.phpfreaks.com/topic/74146-solved-more-control-over-time-needed-or-something-else-to-slow-this-down/#findComment-374426 Share on other sites More sharing options...
djfox Posted October 21, 2007 Author Share Posted October 21, 2007 Cron job? I haven`t heard of those. Link to comment https://forums.phpfreaks.com/topic/74146-solved-more-control-over-time-needed-or-something-else-to-slow-this-down/#findComment-374429 Share on other sites More sharing options...
pocobueno1388 Posted October 21, 2007 Share Posted October 21, 2007 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. Link to comment https://forums.phpfreaks.com/topic/74146-solved-more-control-over-time-needed-or-something-else-to-slow-this-down/#findComment-374432 Share on other sites More sharing options...
Wes1890 Posted October 21, 2007 Share Posted October 21, 2007 Read this http://www.lunarpages.com/new_manual/cronJobs.htm Or search google to find out what a cronjob is Also, in the code you posted, you didn't have == in your IF statement... just so you know Link to comment https://forums.phpfreaks.com/topic/74146-solved-more-control-over-time-needed-or-something-else-to-slow-this-down/#findComment-374433 Share on other sites More sharing options...
djfox Posted October 21, 2007 Author Share Posted October 21, 2007 If my host doesn`t provide that, are there any alternatives? Link to comment https://forums.phpfreaks.com/topic/74146-solved-more-control-over-time-needed-or-something-else-to-slow-this-down/#findComment-374434 Share on other sites More sharing options...
Wes1890 Posted October 21, 2007 Share Posted October 21, 2007 Here is a list of sites that may have your answer http://www.google.com/search?source=ig&hl=en&rlz=&q=alternatives+to+cron+jobs&btnG=Google+Search Link to comment https://forums.phpfreaks.com/topic/74146-solved-more-control-over-time-needed-or-something-else-to-slow-this-down/#findComment-374438 Share on other sites More sharing options...
igor berger Posted October 21, 2007 Share Posted October 21, 2007 Why do you need to update your database every hour? Are you feeding as pet? Link to comment https://forums.phpfreaks.com/topic/74146-solved-more-control-over-time-needed-or-something-else-to-slow-this-down/#findComment-374441 Share on other sites More sharing options...
djfox Posted October 21, 2007 Author Share Posted October 21, 2007 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. Link to comment https://forums.phpfreaks.com/topic/74146-solved-more-control-over-time-needed-or-something-else-to-slow-this-down/#findComment-374446 Share on other sites More sharing options...
igor berger Posted October 21, 2007 Share Posted October 21, 2007 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.. Link to comment https://forums.phpfreaks.com/topic/74146-solved-more-control-over-time-needed-or-something-else-to-slow-this-down/#findComment-374449 Share on other sites More sharing options...
djfox Posted October 21, 2007 Author Share Posted October 21, 2007 Ok, my server does have cron jobs available. Next step most likely is learning it`s commands. Time to research. Thanks for the input guys. Link to comment https://forums.phpfreaks.com/topic/74146-solved-more-control-over-time-needed-or-something-else-to-slow-this-down/#findComment-374452 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.