Solved

curl

Posted on 2002-07-20
7
1,036 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
How do I speed up this PDO query 4 37
php hashing methods 3 44
Php variable to be sent back 3 29
Convert complicated date to yyyy-mm-dd format 22 45
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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.
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…
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…

738 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