Jump to content

Download data if it's been more than a specified amount of time


Recommended Posts

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);
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.