Page 1 of 1

file_get_contents super slow ...use curl?

Posted: Fri Jun 28, 2013 5:50 pm
by Thunderbob
So I'm grabbing some html tags from another site and the load times for file_get_contents is at least 8 seconds.

Here's what my function looks like

(query is submitted through user form)
function getTitle($query) {
     $opts = array('https'=>array('header'=> 'Connection: close'));
     $context = stream_context_create($opts);
     $pattern = "/<title ?.*>(.*)<\/title>/";
     preg_match($pattern, file_get_contents($query,false,$context), $matches);
    return $matches[1];
}
The function works it just takes way too long.
I thought I was cool by adding in $context but it didn't change anything. Some articles online suggested switching to "curl"
tactics and I just wanted to know if that will really work. =)

Re: file_get_contents super slow ...use curl?

Posted: Sat Jun 29, 2013 1:06 am
by Helx
Yes, it is always a good idea to use cURL because there are so many options and things you can do with it (I was quite amazed when I found out you can get the DL/UL speeds in a transfer).

I don't believe that much would change speed-wise. It'd be either your server hasn't got a very good network speed, or the server you're connecting to doesn't.

Still, it may be worth a try. Do let us know how it goes. :)