Solved

curl

Posted on 2002-07-20
7
1,033 Views
Last Modified: 2007-12-19

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
Comment
Question by:kuist
  • 3
  • 3
7 Comments
 
LVL 2

Expert Comment

by:higijj
ID: 7167378
Use the curl_opt like

curl_setopt($ch, CURLOPT_NOBODY, 1);


Regards,
0
 

Author Comment

by:kuist
ID: 7167416
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
 
LVL 5

Accepted Solution

by:
dkjariwala earned 50 total points
ID: 7169365
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:kuist
ID: 7169691
what's the 8192 for?

it's on the 4th line ..

how do I say to just collect the first 4 lines ?
0
 
LVL 5

Expert Comment

by:dkjariwala
ID: 7171603
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
 

Author Comment

by:kuist
ID: 7172694
and 4k is enough to cover the headers ?

how do I tell to read just the first 4k ?
0
 
LVL 5

Expert Comment

by:dkjariwala
ID: 7174225
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question