Solved

curl

Posted on 2002-07-20
7
1,013 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
Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
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…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

705 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

18 Experts available now in Live!

Get 1:1 Help Now