php image caching?

So I started using some php code for image for a server image banner, and it works with the changes I made… however being a php noob, I’m wondering how to make it more efficient so it isn’t always checking the server everytime someone loads the phpcode/image.

Like some sort of timer that stores a last check time in another file, that gets checked each time the code is run makes it so it only actually checks the server status every 5mins or configurable… and if it hasn’t been 5mins since it was last checked, then just send the last image it generated…

How can I do this?

here is most of the main code…

[php]<?php
$config[‘server’][‘ip’] = ‘0.0.0.0’;
$config[‘server’][‘port’] = ‘25565’;

//fetches server information from minequery.
$socket = fsockopen($config[‘server’][‘ip’], $config[‘server’][‘port’], $errno, $errstr, 2);

if ($socket === false){

     $img = imagecreatefrompng ("signature_offline.png");
     header('Content-type: image/png');
     imagepng($img);
     imagedestroy($img);

}
else {
fwrite($socket, “QUERY_JSON\n”);

$responce = stream_get_contents($socket);

$info = json_decode($responce, true);
// create the iamge
$i=rand(0,2);

$img = imagecreatefrompng (“signature_” .$i. “.png”);[/php]

…and on it goes to make the rest of the image…

Sponsor our Newsletter | Privacy Policy | Terms of Service