简体   繁体   English

使用PHP进行图像缓存

[英]Image Caching with PHP

i am trying to learn how to cache an image that is created in PHP, this current piece of PHP wil cache text to a file, but i want to get it to cache an image called 'my_barcode.png' to the cache folder, any help would be greatly appreciated. 我正在尝试学习如何缓存在PHP中创建的图像,该当前PHP会将文本缓存到文件中,但是我想获取它以将名为“ my_barcode.png”的图像缓存到缓存文件夹中,帮助将不胜感激。

<?php

$h = opendir('data/');
$chace = 'cache/test.cache.php';

if(file_exists($chace))
{
include($chace);
}
else
{
$result = NULL;
while (($file = readdir($h)) !=false)
{
$result .= $file. '<br />';
}

closedir($h);

echo $result;

$fs = fopen($chace, 'w+');
fwrite($fs, $result);
fclose($fs);
}
?>

If the purpose is to serve cached files, PHP should create them when not existing but the http server (such as Apache) should be serving the static files if they exist. 如果目的是提供缓存的文件,则PHP应该在不存在时创建它们,但是http服务器(例如Apache)应该在提供静态文件时(如果存在)创建它们。 Implementing cache the way you did takes too many resources as PHP is still called. 以这种方式实现缓存需要占用太多资源,因为仍然调用PHP。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM