找回密码
 注册加入

扫一扫,极速登录

QQ登录

只需一步,快速开始

搜索
查看: 4645|回复: 0

简单改动减轻附件前端负载

[复制链接]
发表于 2011-3-20 11:38:55 | 显示全部楼层 |阅读模式
目前附件模块虽然已经经过了优化,但是在对于附件下载两比较大的网站,还是会造成服务器内存的过多使用,所以整理了一下两种改动,一种是针对系统自带远程附件的改动,另外一种是对于使用了 NFS 作为附件存储的改动。

1.对于远程附件的修改方法:
打开:source\module\forum\forum_attachment.php 找到:

  1. if(!@readfile($_G['setting']['ftp']['attachurl'].'forum/'.$file)) {
复制代码

修改为:

  1. if(!@fread($_G['setting']['ftp']['attachurl'].'forum/'.$file,100)) {
复制代码

即可减轻远程附件对服务器内存的占用。

2.对于使用了NFS附件的修改方法
首先需要对 NFS 的附件目录给一个域名,能够保证该域名能访问到 附件目录的文件,同时从NFS上做好防盗链的设置。
然后修改 config\config_global.php 文件:

  1. // -------------------------  CONFIG DOWNLOAD  -------------------------- //
  2. $_config['download']['readmod'] = 2;
  3. $_config['download']['xsendfile']['type'] = '0';
  4. $_config['download']['xsendfile']['dir'] = '/down/';
复制代码

修改为:

  1. // ------------------------- CONFIG DOWNLOAD -------------------------- //
  2. $_config['download']['readmod'] = 2;
  3. $_config['download']['xsendfile']['type'] = '4';
  4. $_config['download']['xsendfile']['dir'] = '/down/';
  5. $_config['download']['xsendfile']['remoteurl'] = 'xxxxxxxx';  //NFS 能够访问到底附件目录,请先测试能访问附件例如 http://img.discuz.net/data/attachment/forum/
复制代码

然后修改文件:source\module\forum\forum_attachment.php 找到:
  1. case 3: $cmd = 'X-Sendfile'; $url = $filename; break;
复制代码

增加
  1. case 4: $cmd = 'location'; $url = $xsendfile['remoteurl'].$attach['attachment'];break;
复制代码

这样便做到了附件流量的分流~~减轻了 web 服务器的负载。
您需要登录后才可以回帖 登录 | 注册加入  

本版积分规则

Archiver|手机版|小黑屋|Discuz!扩展中心 ( 浙ICP备14042422号-1 )|网站地图QQ机器人

GMT+8, 2024-4-29 18:55 , Processed in 0.173170 second(s), 10 queries , Gzip On, Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表