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)
[syntax=php]
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];
}
[/syntax]
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. =)
file_get_contents super slow ...use curl?
-
- Posts: 46
- Joined: Sat Jun 30, 2012 12:31 pm
Re: file_get_contents super slow ...use curl?
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.
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.