tags:

views:

154

answers:

3

Im running a video link aggregator, and I have a script that checks to see if the video was deleted from site. Its done by getting the HTML output of the link, and checking against target keywords.

Currently I use file_get_contents() to get the html code of the link. The problem is, some sites redirect to another URL if the link is removed.

Using curl solves the problem... but is it gonna use more server resources? I run the checker script every 10 minutes, and it checks 1000 links (there are 300,000 links in the DB).

The code that I wanna use is as follows:

$Curl_Session = curl_init('http://www.domain.com');
curl_setopt ($Curl_Session, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($Curl_Session, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec ($Curl_Session);
curl_close ($Curl_Session);
+2  A: 

If any thing, it will be faster. If your php already compiled with curl then you will be using the same amount of memory whether your calling curl or not.

However, I would be concerned about following these links. you can get into a loop this way or hit a lot of hops thus slowing down your script. So i would add a max CURLOPT_MAXREDIRS

Also, are you downloading those videos to see if they exists? I would just get the remote filesize:

curl_setopt($Curl_Session, CURLOPT_HEADER, false); curl_setopt($Curl_Session, CURLOPT_NOBODY, true);

to get size $info = curl_getinfo(); echo $info[‘download_content_length’]

discovlad
Another way to get size is:$size = array_change_key_case(get_headers($url, 1)); if (is_array($size['content-length'])) $size = $size['content-length'][count($size['content-length'])-1]; else $size = $size['content-length']; echo $size;
Sbm007
A: 

The CURL library cant be slower than the network, so dont worry about it. A faster internet connection and some way of distributing this checking will help you a lot more than any library out there, no matter how slow it would be.

Quamis