Curl v/s file_get_contents性能在同一台服务器上的文件


curl v/s file_get_contents performance for a file on same server

目前我正在使用file_get_contents从缓存中获取文件(即来自同一服务器的文件),我不需要CURL提供的不同选项。如果我使用curl而不是file_get_contents,我会得到任何性能优势吗?

$cachepath="/dev/shm/cache";
$cachedfile=$cachepath."/".sha1($this->URL['href']);
$content=file_get_contents($cachedfile);
echo $content;

如果使用CURL,性能会更差。

为什么?

因为它发起一个HTTP请求,通过网络,调用HTTP服务器上的响应,启动一些进程(例如PHP),获取文件,然后返回到CURL。

如果你使用file_get_contents(),你只是在同一个进程中获取文件。