Discuz! 簡(jiǎn)單改動(dòng)減輕附件前端負(fù)載

字號(hào):


    目前附件模塊雖然已經(jīng)經(jīng)過了優(yōu)化,但是在對(duì)于附件下載兩比較大的網(wǎng)站,還是會(huì)造成服務(wù)器內(nèi)存的過多使用,所以整理了一下兩種改動(dòng),一種是針對(duì)系統(tǒng)自帶遠(yuǎn)程附件的改動(dòng),另外一種是對(duì)于使用了 NFS 作為附件存儲(chǔ)的改動(dòng)。
    1.對(duì)于遠(yuǎn)程附件的修改方法:
    打開:sourcemoduleforumforum_attachment.php 找到:
    if(!@readfile($_G['setting']['ftp']['attachurl'].'forum/'.$file)) {
    修改為:
    if(!@fread($_G['setting']['ftp']['attachurl'].'forum/'.$file,100)) {
    即可減輕遠(yuǎn)程附件對(duì)服務(wù)器內(nèi)存的占用。
    2.對(duì)于使用了NFS附件的修改方法
    首先需要對(duì) NFS 的附件目錄給一個(gè)域名,能夠保證該域名能訪問到 附件目錄的文件,同時(shí)從NFS上做好
    防盜鏈
    的設(shè)置。
    然后修改 configconfig_global.php 文件:
    // ------------------------- CONFIG DOWNLOAD -------------------------- //
    $_config['download']['readmod'] = 2;
    $_config['download']['xsendfile']['type'] = '0';
    $_config['download']['xsendfile']['dir'] = '/down/';
    一段修改為:
    // ------------------------- CONFIG DOWNLOAD -------------------------- //
    $_config['download']['readmod'] = 2;
    $_config['download']['xsendfile']['type'] = '4';
    $_config['download']['xsendfile']['dir'] = '/down/';
    $_config['download']['xsendfile']['remoteurl'] = 'xxxxxxxx'; //NFS 能夠訪問到底附件目錄,請(qǐng)先測(cè)試能訪問附件例如 http://img.discuz.net/data/attachment/forum/
    然后修改文件:sourcemoduleforumforum_attachment.php 找到:
    case 3: $cmd = 'X-Sendfile'; $url = $filename; break;
    增加:
    case 4: $cmd = 'location'; $url = $xsendfile['remoteurl'].$attach['attachment'];break;
    這樣便做到了附件流量的分流~~減輕了 web 服務(wù)器的負(fù)載。