Solved

curl

Posted on 2002-07-20
7
1,017 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

914 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now