fpassthru()替代方案

时间:2011-05-22 17:32:26

标签: php wordpress minify

我在我的Wordpress博客上使用WP-MINIFY插件,但由于我服务器的安全配置,fpassthru()功能被禁用。所以,我必须找到另一种方法,所以我可以编辑插件。

我在缩小的文件上收到此错误:


警告:fpassthru()因安全原因而被停用 /home/blablabla/public_html/wp-content/plugins/wp-minify/min/lib/Minify/Cache/File.php 在线 84

这是使用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);            
    }
}

你有什么想法吗?

2 个答案:

答案 0 :(得分:3)

echo stream_get_contents($fp);

(而不是fpassthru行)做同样的事情,只有更多的内存消耗(并且不如fpassthru优化)。

答案 1 :(得分: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);            
    }
}