码迷,mamicode.com
首页 > 系统相关 > 详细

nginx+memcached缓存图片

时间:2017-06-28 13:18:48      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:key   ror   test   cal   ring   pac   域名   line   page   

1.nginx的配置如下:

location ^~ /images/ {
    set $memcached_key  "$uri"; #用URI作为key去memcached中去读取内容
    memcached_pass      127.0.0.1:11211;
    memcached_connect_timeout 5s;
    memcached_read_timeout 5s;
    memcached_send_timeout 5s;
    memcached_buffer_size 32k;
    error_page     404 502 504 = @fallback;
}
location @fallback {
    proxy_pass     http://backend;
}
 
2.使用PHP向memcached写入一张图片:
<?php
$pic = file_get_contents(‘./test.jpg‘);
$memcache = new Memcache;
$memcache->connect(‘localhost‘, 11211);
$memcache->add(‘/images/test.jpg‘, $pic, false, 0); //这里设置缓存不过期
$memcache->close();
 
3.查看图片
根据域名,使用浏览器访问:http://test.localhost/images/test.jpg
 

nginx+memcached缓存图片

标签:key   ror   test   cal   ring   pac   域名   line   page   

原文地址:http://www.cnblogs.com/cocoqi/p/7088942.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!