I know that file_get_contents can be used to retrieve the source of a webpage, but I want to know the most efficient way.
I have an old class I made a long time ago that uses something like this:
$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);
Is this the best way? By most efficient I mean returns the fastest results.