Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php fpassthru()备选方案_Php_Wordpress_Minify - Fatal编程技术网

Php fpassthru()备选方案

Php fpassthru()备选方案,php,wordpress,minify,Php,Wordpress,Minify,我在Wordpress博客上使用插件,但由于服务器的安全配置,该功能被禁用。所以,我必须找到另一种方法,这样我才能编辑插件 我在缩小的文件上遇到此错误: 警告:第84行的/home/blabla/public_html/wp content/plugins/wp minify/min/lib/minify/Cache/File.php中,由于安全原因,已禁用fpassthru() 这是使用fpassthru的函数: /** * Send the cached content to outpu

我在Wordpress博客上使用插件,但由于服务器的安全配置,该功能被禁用。所以,我必须找到另一种方法,这样我才能编辑插件

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


警告:第84行的/home/blabla/public_html/wp content/plugins/wp minify/min/lib/minify/Cache/File.php中,由于安全原因,已禁用fpassthru()

这是使用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);            
    }
}
你有什么想法吗?

你可以使用:

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);            
    }
}

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

我不喜欢用php处理文件。我将删除
fpassthru()
,然后添加这一行,而不是
fpassthru()
,对吗?请参阅我的更新答案,以及新函数的完整版本。谢谢。与@phihag的答案相比,此方法更优化?@Eray否,这将(如果只是稍微)慢一些,因为需要额外的系统调用来确定文件的大小。无论使用哪种解决方案,在开始任何输出之前,整个文件都将被读取到内存中。此外,如果在调用
filesize
fread
之间添加另一个进程而不锁定文件,则此版本将失败。(但这是一个非常牵强的场景)。在这种情况下,您将只读取文件的一部分。@Eray因为
fread($fp,filesize())
在最好的情况下会明显变慢,在最坏的情况下会变慢2*左右,并且不必要地引入上述错误,如我的回答所述,我会选择
stream\u get\u contents
。我很困惑提供商为什么会禁用
fpassthru
。它只不过是一个文件读取,正如答案所示,很容易替换。这很可能是由于错误而被阻止的(因为这是一个exec命令)。你应该向你的主机提供商开一张罚单。
echo stream_get_contents($fp);