Discuz! 簡單改動減輕附件前端負載

字號:


    目前附件模塊雖然已經(jīng)經(jīng)過了優(yōu)化,但是在對于附件下載兩比較大的網(wǎng)站,還是會造成服務(wù)器內(nèi)存的過多使用,所以整理了一下兩種改動,一種是針對系統(tǒng)自帶遠程附件的改動,另外一種是對于使用了 NFS 作為附件存儲的改動。
    1.對于遠程附件的修改方法:
    打開:sourcemoduleforumforum_attachment.php 找到:
    if(!@readfile($_G['setting']['ftp']['attachurl'].'forum/'.$file)) {
    修改為:
    if(!@fread($_G['setting']['ftp']['attachurl'].'forum/'.$file,100)) {
    即可減輕遠程附件對服務(wù)器內(nèi)存的占用。
    2.對于使用了NFS附件的修改方法
    首先需要對 NFS 的附件目錄給一個域名,能夠保證該域名能訪問到 附件目錄的文件,同時從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 能夠訪問到底附件目錄,請先測試能訪問附件例如 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ù)器的負載。