我知道 file_get_contents 可用于检索网页的来源,但我想知道最有效的方法。
我有一个很久以前制作的旧课程,它使用这样的东西:
$this->socket = fsockopen($this->host, 80);
fputs($this->socket, 'GET ' . $this->target . ' HTTP/1.0' . "\n");
fputs($this->socket, 'Host: ' . $this->host . "\n");
fputs($this->socket, 'User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9b5) Gecko/2008050509 Firefox/3.0b5' . "\n");
fputs($this->socket, 'Connection: close' . "\n\n");
$this->source = '';
while(!feof($this->socket))
{
$this->source .= fgets($this->socket, 128);
}
fclose($this->socket);
这是最好的方法吗?最有效的意思是返回最快的结果。