【发布时间】:2012-01-26 10:56:36
【问题描述】:
我有一个 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
【问题讨论】:
标签: php performance file-exists