• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1059
  • Last Modified:

curl


Here I'm using curl to verify a list of link (avi/mpg) to be sure there is not 404.

what I do is

          $ch = curl_init ($url);
               curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
               curl_setopt($ch, CURLOPT_HEADER, 1);
               $result2 = curl_exec ($ch);
          curl_close ($ch);

          print $result2;

and verify that they have the Content-Type: video/x-msvideo header

but how to stop curl from downloading the whole avi/mpg ?!
I just want the headers
0
kuist
Asked:
kuist
  • 3
  • 3
1 Solution
 
higijjCommented:
Use the curl_opt like

curl_setopt($ch, CURLOPT_NOBODY, 1);


Regards,
0
 
kuistAuthor Commented:
yeah.. but it takes for ever to check like 10 of them!

maybe there is a way to do it with socket function?!

Please advise!
0
 
dkjariwalaCommented:
Try the following code on a VALID url.
See on which line the Content header is coming and verify its AVI/MPG and you are there.

JD

<?php


$url = "http://yoururl/goes/here";

$fp = fsockopen($url,80,$errno,$errstr,30);

if(! $fp )
     printf("URL is not valid or it can not be accessed.");


$read_header= TRUE;

$url_header =  array();

while($read_header)
{
          $line = fgets($fp,8192);
          if(strlen($line) == 0)
               $read_header = false;
          else
               $url_header[]= $line;
}


?>
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
kuistAuthor Commented:
what's the 8192 for?

it's on the 4th line ..

how do I say to just collect the first 4 lines ?
0
 
dkjariwalaCommented:
8192 is number of bytes, its 8k basically. You can keep it to say 4096 - 4k.

It means data will be read in 4k chunk from socket.

JD
0
 
kuistAuthor Commented:
and 4k is enough to cover the headers ?

how do I tell to read just the first 4k ?
0
 
dkjariwalaCommented:
replace existing $line...with

$line = fgets($fp,4096); //it should read 4k.

And yeah it will suffice though try and test it. thats the best way !!

JD
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now