2011-05-22 171 views
2

我在我的WordPress博客上使用WP-MINIFY插件,但由於我的服務器的安全配置,fpassthru()函數被禁用。所以,我必須找到一種替代方式,所以我可以編輯插件。fpassthru()替代

我越來越縮小的上檔這樣的錯誤:


警告:fpassthru()已被禁用在/家庭/ blablabla /的public_html /可溼性粉劑內容/插件/ WP-安全原因縮小/分鐘/ LIB /縮減大小/緩存/ File.php上線

這是使用fpassthru函數:

/** 
* Send the cached content to output 
* 
* @param string $id cache id (e.g. a filename) 
*/ 
public function display($id) 
{ 
    if ($this->_locking) { 
     $fp = fopen($this->_path . '/' . $id, 'rb'); 
     flock($fp, LOCK_SH); 
     fpassthru($fp); 
     flock($fp, LOCK_UN); 
     fclose($fp); 
    } else { 
     readfile($this->_path . '/' . $id);    
    } 
} 

你有什麼想法嗎?

+3

我很困惑,爲什麼提供者會禁用'fpassthru'。它只不過是一個文件讀取,而且答案顯示很容易替換。這很可能是因爲錯誤而被阻止,並且** ['passthru'](http://php.net/passthru)**應該是(因爲這是一個exec命令)。您應該與您的託管服務提供商打開一張票。 – mario 2011-05-22 17:43:56

回答

2

你可以使用:

public function display($id) 
{ 
    $filename=$this->_path . '/' . $id; 
    if ($this->_locking) { 
     $fp = fopen($filename, 'rb'); 
     flock($fp, LOCK_SH); 
     //fpassthru($fp); 
     $out=fread($fp,filesize($filename)); 
     echo $out; 
     flock($fp, LOCK_UN); 
     fclose($fp); 
    } else { 
     readfile($filename);    
    } 
} 
+0

我與用php處理文件不相似。我將刪除'fpassthru()'的行,然後添加這一行,而不是'fpassthru()'對嗎? – Eray 2011-05-22 17:36:53

+1

查看我更新的答案,並帶有完整版本的新功能。 – 2011-05-22 17:42:03

+0

謝謝。當我們和@ phihag的答案比較時,這種方法更加優化了嗎? – Eray 2011-05-22 17:48:19

3
echo stream_get_contents($fp); 

(而不是fpassthru線)做同樣的事情,只能用更多的內存消耗(比fpassthru少優化)。