Avatar Caching system [REL]
Hello,
i have code a advanced avatar caching system, because i'm boring..
PHP Code:
<?phpheader('Content-Type: image/png');// Avatar caching system// CODER: Karim, AKA iFuckR
// CONFIGdefine("HOST", "127.0.0.1"); // Gebruiker 127.0.0.1 voor snelheid!define("GEBRUIKER", "root"); // Gebruiker, meestal 'root'define("WACHTWOORD", "123"); // Wachtwoord, moet voor zichzelf sprekendefine("DATABASE", "bcstorm"); // Database naam.$map = './avatars'; // De map waar alles word opgeslagen.define("HOTEL", "habbo.co.uk"); // Het hotel waar de data vandaan moet komen, gebruik geen .com!// Verander niks onder deze lijn! Anders kan het systeem langzaam worden, of verknalt worden enzo.. xd
mysql_connect(HOST, GEBRUIKER, WACHTWOORD) or die ('FATALE FOUT: Onmogelijk om met MySQL server te verbinden!'); mysql_select_db(DATABASE) or die ('FATALE FOUT: Onmogelijk om te verbinden met database!');
if (!is_dir($map)) { if (!mkdir($map, 0, true)) { die('FATALE FOUT: Onmogelijk om folder aan te maken!'); } }
$figure = $_GET['figure'];
if(isset($_GET['size'])){$size = $_GET['size'];} else { $size= 'b';}
if(isset($_GET['direction'])){$direction = $_GET['direction'];} else { $direction = '2';}
if(isset($_GET['head_direction'])){$head = $_GET['head_direction'];} else { $head = '2'; }
if(isset($_GET['gesture'])){$gesture = $_GET['gesture'];} else { $gesture = '';}
$lookhash = md5("$figure$size$direction$head$gesture");
if (file_exists("$map/$lookhash.png")) { $finalavatar = require("$map/$lookhash.png"); } else { $habbo = file_get_contents("http://".HOTEL."/habbo-imaging/avatarimage?figure=".$figure."&size=".$size."&direction=".$direction."&head_direction=".$head."&gesture=".$gesture.""); $fp = fopen("$map/$lookhash.png", 'w'); fwrite($fp, $habbo); fclose($fp); $finalavatar = $habbo;}
/// JAJAJAJAJ! EINDELIJK! DAAR IS DIE DAN, EN VELE MALEN SNELLER :o!echo $finalavatar;
How it works.
You make a php file, avatars.php or something, and it makes the source.
The first time the script is used, there will a folder created ..
and there are all avatars stored.
The first time this avatar being watched, get stored on habbo hotel, to your web server.
The next time you watched avatar, hosts.allow the avatar from the server read it does not use the internet, so equal * rads * from the server ..
Re: Avatar Caching system [REL]
When you have a lot of users your avatars folder/mysql database will become bigger than 1gb, so a very bad idea..
Re: Avatar Caching system [REL]
When will people learn that caching speeds up load time but ruins disk space!? :<
Re: Avatar Caching system [REL]
Quote:
Originally Posted by
FullmetalPride
When will people learn that caching speeds up load time but ruins disk space!? :<
Yeah use this on a hotel with daily 1000+ online and you need to get some more disk space. Think this is usefull for hotels with a max of 75 online.
Re: Avatar Caching system [REL]
Quote:
Originally Posted by
tdid
Yeah use this on a hotel with daily 1000+ online and you need to get some more disk space. Think this is usefull for hotels with a max of 75 online.
22,000 images = 36.7 MB
not bad?
Re: Avatar Caching system [REL]
Quote:
Originally Posted by
Thekguy
22,000 images = 36.7 MB
not bad?
The problem is there are more than a billion possibilities. Ask people who have tried this what happens after a month of use.
Re: Avatar Caching system [REL]
Quote:
Originally Posted by
FullmetalPride
When will people learn that caching speeds up load time but ruins disk space!? :<
He was bored so he coded something for the community? I didn't know that was so bad.
To the OP, good release, it'll help with small hotels who are looking to use this :).
Re: Avatar Caching system [REL]
can anny1 give me some of his avatar images? (.png)
just alot :p
Re: Avatar Caching system [REL]
<?php
header('Content-Type: image/png');
$path = trim($_SERVER['PATH_INFO'], '/');
$db = new MySQLi('p:localhost', 'root', 'admin', 'phoenix');
if ($row = $db->query('SELECT image FROM avatars WHERE uri = \''.$path.'\' LIMIT 1')->fetch_assoc())
{
exit($row['image']);
}
$data = file_get_contents('http://www.habbo.nl/habbo-imaging/avatarimage?'.$path);
$db->query('INSERT INTO avatars (uri, image) VALUES(\''.$db->real_escape_string($path).'\', \''.$db->real_escape_string($data).'\')');
echo $data;
?>
Better?
Re: Avatar Caching system [REL]
Quote:
Originally Posted by
Thekguy
22,000 images = 36.7 MB
not bad?
Indeed not bad at all.
Re: Avatar Caching system [REL]
Quote:
Originally Posted by
azaidi
<?php
header('Content-Type: image/png');
$path = trim($_SERVER['PATH_INFO'], '/');
$db = new MySQLi('p:localhost', 'root', 'admin', 'phoenix');
if ($row = $db->query('SELECT image FROM avatars WHERE uri = \''.$path.'\' LIMIT 1')->fetch_assoc())
{
exit($row['image']);
}
$data = file_get_contents('http://www.habbo.nl/habbo-imaging/avatarimage?'.$path);
$db->query('INSERT INTO avatars (uri, image) VALUES(\''.$db->real_escape_string($path).'\', \''.$db->real_escape_string($data).'\')');
echo $data;
?>
If you use this with my QuickTPL or UberCMS with a cron job which cleans the table every week, it will really help you speed up your site.
Re: Avatar Caching system [REL]
Thanks. But i aint gonna use it.
Re: Avatar Caching system [REL]
No it is not bad.
If you have 1000 online, and 250,000 users ..
Will you approximately 8 million images have been cached but 8 gb.
Avatar Caching system [REL]
If I am not mistaking with phoenix you can use last_updated to detect if the look of the user has changed and delete the old image.
Sent from my BlackBerry 9800 using Tapatalk