Discuz如何改动减轻附件前端的负载

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

1.对于远程附件的修改方法:
打开:source\module\forum\forum_attachment.php 找到:
  • if(!@readfile($_G['setting']['ftp']['attachurl'].'forum/'.$file)) {

[color=rgb(51, 102, 153) !important]复制代码

修改为:
  • if(!@fread($_G['setting']['ftp']['attachurl'].'forum/'.$file,100)) {


[color=rgb(51, 102, 153) !important]复制代码

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

2.对于使用了NFS附件的修改方法
首先需要对 NFS 的附件目录给一个域名,能够保证该域名能访问到 附件目录的文件,同时从NFS上做好防盗链的设置。
然后修改 config\config_global.php 文件:
  • // -------------------------  CONFIG DOWNLOAD  -------------------------- //
  • $_config['download']['readmod'] = 2;
  • $_config['download']['xsendfile']['type'] = '0';
  • $_config['download']['xsendfile']['dir'] = '/down/';


[color=rgb(51, 102, 153) !important]复制代码

一段修改为:
  • // ------------------------- CONFIG DOWNLOAD -------------------------- //
  • $_config['download']['readmod'] = 2;
  • $_config['download']['xsendfile']['type'] = '4';
  • $_config['download']['xsendfile']['dir'] = '/down/';
  • $_config['download']['xsendfile']['remoteurl'] = 'xxxxxxxx';  //NFS 能够访问到底附件目录,请先测试能访问附件


[color=rgb(51, 102, 153) !important]复制代码

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

[color=rgb(51, 102, 153) !important]复制代码

增加:
  • case 4: $cmd = 'location'; $url = $xsendfile['remoteurl'].$attach['attachment'];break;

[color=rgb(51, 102, 153) !important]复制代码

这样便做到了附件流量的分流~~减轻了 web 服务器的负载。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|SetYun ( 辽ICP备16005250号

GMT+8, 2024-4-17 04:24 , Processed in 0.039089 second(s), 4 queries , File On.

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

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