Home  >  Article  >  php教程  >  php将gd生成的图片缓存到memcache的小例子

php将gd生成的图片缓存到memcache的小例子

WBOY
WBOYOriginal
2016-06-13 11:51:371050browse

复制代码 代码如下:


//开始缓存图片         

        ob_start();//启用输出缓存,暂时将要输出的内容缓存起来 

        imagejpeg($newimage,false,$quality);//输出 

        $data = ob_get_contents();//获取刚才获取的缓存 

        ob_end_clean();//清空缓存 

        $mem =get_memcache();//自己修改 

        $mem->set($mem_key,$data,720000);//将刚才获取的输出存到memcache里 

        echo $data;//输出图片 

      然后显示的时候这样

        $mem = get_memcache();//自己修改 
        $data = $mem->get($mem_key);

        if($data) {

            echo $data;

            exit();

        }

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn