优化图像输出性能

时间:2012-01-26 10:56:37

标签: php performance file-exists

我有一个php文件,用于检查图像是否可用。如果是,则图像将返回给用户,否则将创建它然后返回给用户。

if(file_exists($filepath)) {
    $fp = fopen($filepath, 'rb'); # stream the image directly from the cachefile
    fpassthru($fp);
    exit;
} 

我想要优化这个我可以跳过“file_exists”调用并尝试“fopen”它,如果返回“false”我创建图像,否则我直接返回它(这是正确的吗?)。

我想知道的是,这是用PHP加载图像的最快方法吗?在此之前我使用了imagepng($image),但是读到fpassthru更快: http://www.php.net/manual/en/function.imagepng.php#103787

0 个答案:

没有答案