Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

GD2 cache i provera starosti cache-a

[es] :: PHP :: GD2 cache i provera starosti cache-a

[ Pregleda: 1695 | Odgovora: 5 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

turshija
Boris Vujicic
KGB Hosting
Novi Sad

Član broj: 240915
Poruke: 27
93.86.225.*

Sajt: www.turshija.com


+1 Profil

icon GD2 cache i provera starosti cache-a09.12.2009. u 22:10 - pre 175 meseci
Pozdrav ...
Igram se malo u PHP-u sa dinamickim slikama koje se refreshuju svakih par minuta ...
Koristim GD2 biblioteku ...
E sada ...
Zelim da ubacim cache i ovo mi zeluje kao okej resenje:

Code:
$image_path = "../image-cache/nesto.png";
 
if (file_exists($image_path)) {
    readfile($image_path);
}else{
  // kod ovde

    ImagePNG($new_image);
    ImagePNG($new_image, $image_path);
    ImageDestroy($new_image);
}


E ali jedini problem je sto ovde ako postoji slika, ucita je iz kesha, a ako ne postoji generise drugu pa je cuva u kesh ...
A meni treba taj cache da bude validan par minuta, posle toga da ga ne gleda (da generise novu sliku preko njega) ...
Kako u ovu liniju "if (file_exists($image_path))" da ubacim proveru tipa "slika napravljena pre manje od 5 minuta" ? :)

Hvala puno ... :)

ceo kod: http://www.design-ireland.net/...rticle.php%3Foid%3D00000000057
mysql_query("DELETE stupidity FROM earth") or die("Stupidity");
 
Odgovor na temu

Nemke_BG

Član broj: 163822
Poruke: 341
91.148.87.*

Jabber: Nemke_BG@elitesecurity.org
Sajt: https://www.nmdesign.rs


+45 Profil

icon Re: GD2 cache i provera starosti cache-a09.12.2009. u 23:20 - pre 175 meseci
isti je odgovor kao i kad si ovo pitao....

http://www.elitesecurity.org/t382541-PHP-last-file-access

samo sto posto utvrdis da ti je istekao kes obrises stari fajl i kreiras novi...
...
 
Odgovor na temu

turshija
Boris Vujicic
KGB Hosting
Novi Sad

Član broj: 240915
Poruke: 27
93.86.225.*

Sajt: www.turshija.com


+1 Profil

icon Re: GD2 cache i provera starosti cache-a09.12.2009. u 23:36 - pre 175 meseci
Hah, hvala ... :)
Ma gledao sam stat(), ali nisam primetio da ima mtime, a to je tacno ono sto mi treba ... :)
debil ... :D

edit:

resio sam problem sa ovim:

Code:

$cache_path = "./cache/banner1_$_GET[id]_$_GET[color].png";

if ($stat = @stat($cache_path))
    $mtime = time() - $stat['mtime'];

if ((file_exists($cache_path)) && ($mtime<300)) {
     readfile($cache_path);
} else {

// kreiranje slike
//


// output
imagepng($im);
imagepng($im, $cache_path);
imagedestroy($im);
}


[Ovu poruku je menjao turshija dana 10.12.2009. u 00:49 GMT+1]
mysql_query("DELETE stupidity FROM earth") or die("Stupidity");
 
Odgovor na temu

Nemke_BG

Član broj: 163822
Poruke: 341
*.static.sbb.rs.

Jabber: Nemke_BG@elitesecurity.org
Sajt: https://www.nmdesign.rs


+45 Profil

icon Re: GD2 cache i provera starosti cache-a10.12.2009. u 08:30 - pre 175 meseci
nema ne cemu, nego sta mislis da odradis to ovako...

Code:


$cache_path = "./cache/banner1_$_GET[id]_$_GET[color].png";

if (file_exists($cache_path) && ($stat = stat($cache_path)) && ((time() - $stat['mtime']) < 300))
    readfile($cache_path);
else
{
    // kreiranje slike
    //

    // output
    imagepng($im);
    imagepng($im, $cache_path);
    imagedestroy($im);
}


...
 
Odgovor na temu

turshija
Boris Vujicic
KGB Hosting
Novi Sad

Član broj: 240915
Poruke: 27
93.86.224.*

Sajt: www.turshija.com


+1 Profil

icon Re: GD2 cache i provera starosti cache-a11.12.2009. u 14:10 - pre 175 meseci
Hvala ... :)
Pitanje:

u tom tvom primeru ovaj deo ($stat = stat($cache_path)) nece zakucati ako $cache_path ne postoji ?
mysql_query("DELETE stupidity FROM earth") or die("Stupidity");
 
Odgovor na temu

Nemke_BG

Član broj: 163822
Poruke: 341
109.106.228.*

Jabber: Nemke_BG@elitesecurity.org
Sajt: https://www.nmdesign.rs


+45 Profil

icon Re: GD2 cache i provera starosti cache-a12.12.2009. u 00:47 - pre 175 meseci
nece, ali se bila provukla jedna greskica.......

umesto

Code:
if (file_exists($cache_path) && ($stat = stat($cache_path)) && ((time() - $stat['mtime']) < 300))


treba

Code:
if (file_exists($cache_path) && ($stat = stat($cache_path)) && ((time() - $stat['mtime']) > 300))


tj. treba da je vece od 300 jer je u tom slucaju istekao kes a ne obratno...
...
 
Odgovor na temu

[es] :: PHP :: GD2 cache i provera starosti cache-a

[ Pregleda: 1695 | Odgovora: 5 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.