sp@rky13 Posted August 1, 2009 Share Posted August 1, 2009 Ok so what I want to do is that if a person accesses a php page and it has been more than one hour since the last download, then it should download the data. How can I do this? This is my download code currently for one of my 3 pieces of data: <?php ini_set(memory_limit,"80M"); $current_world = 28; $connection = mysql_connect("localhost","",""); if (!$connection){ die("Could not connect: ". mysql_error()); } $db_database = "wwwspark_tribalwars"; $db_select = mysql_select_db($db_database); if(!$db_select){ die("Could not select the database: <br>". mysql_error()); } $delete = mysql_query("DELETE FROM villages_en".$current_world." WHERE 1=1"); if(!$delete){ die("Could not delete previous database---world28_villages". mysql_error()); } $lines = gzfile('http://en'.$current_world.'.tribalwars.net/map/village.txt.gz'); if(!is_array($lines)) die("File could not be opened"); foreach($lines as $line) { list($id, $name, $x, $y, $player, $points, $rank) = explode(',', $line); $name = urldecode($name); $name = addslashes($name); $query = mysql_query("INSERT INTO villages_en".$current_world." SET id='$id', name='$name', x='$x', y='$y', player='$player', points='$points', rank='$rank'"); if(!$query){ die("Could not insert the database: <br>". mysql_error()); } } mysql_close($connection); ?> Quote Link to comment https://forums.phpfreaks.com/topic/168352-download-data-if-its-been-more-than-a-specified-amount-of-time/ Share on other sites More sharing options...
sp@rky13 Posted August 2, 2009 Author Share Posted August 2, 2009 Any ideas???? Also, along with downloading the info I can download a time stamp into mysql, so, maybe the code could check to see if it had been i hour since that time sytamp and if so download the info Quote Link to comment https://forums.phpfreaks.com/topic/168352-download-data-if-its-been-more-than-a-specified-amount-of-time/#findComment-888660 Share on other sites More sharing options...
fenway Posted August 3, 2009 Share Posted August 3, 2009 Yes, you'll have to store the time of the last download. Quote Link to comment https://forums.phpfreaks.com/topic/168352-download-data-if-its-been-more-than-a-specified-amount-of-time/#findComment-889978 Share on other sites More sharing options...
sp@rky13 Posted August 3, 2009 Author Share Posted August 3, 2009 So would I do that in a mysql table and have it put an id next to it and then the code would check the largest ID or something or what?? Quote Link to comment https://forums.phpfreaks.com/topic/168352-download-data-if-its-been-more-than-a-specified-amount-of-time/#findComment-890099 Share on other sites More sharing options...
fenway Posted August 4, 2009 Share Posted August 4, 2009 Just store a timestamp associated with each download. Quote Link to comment https://forums.phpfreaks.com/topic/168352-download-data-if-its-been-more-than-a-specified-amount-of-time/#findComment-890912 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.