Re: Simple HTTP request, with "Range" header

From: Date: Wed, 13 Aug 2003 05:14:39 +0000
Subject: Re: Simple HTTP request, with "Range" header
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-159393@lists.php.net to get a copy of this message
* Thus wrote Ken (kenzo@free-music.com): > What I want to do is write something simple in PHP that makes an HTTP request, takes the data > received, and passes it through. Ok.. sounds good so far :) > Specifically, I am hoping to retrieve just a part of a file from the web server. If I wanted > the whole file I would just do header("Location:..."); > This technically wont be a pass through, you might want to do a read file if you want to hide the url your actually fetching. > I imagine I would want to form a basic get header request, with URL, whatever else I need, and > a "Range:bytes=1000-2000" header. If I understand correctly, the (HTTP/1.1) web server > would return the document I want, just bytes 1000-2000. > The problem with dealing with HTTP/1.1 is you have to make sure your script is HTTP/1.1 compliant, which there are a lot of gotchas to deal with. For example, some web servers will send back the data in chunks instead of just stream the file to you. So you have to parse the size of the chunk and then fread that size into your buffer. Now I think you can get by with a range: header when you request a document as HTTP/1.0, its been a while since I've acually done that so cant remember if I had to use HTTP/1.1 or not. > Then I would take whatever is received and use a pass through function to pipe it out. > > I realize it might be simpler to do a file read (assuming I'm doing this on the very same > server as the document), and then just seek to the given position and pass through whatever I wish. > As far as that option goes, I was concerned that this might somehow be less efficient than the above > scenario, which would be letting the web server do the seeking. But maybe both options are > inefficient. Or maybe they're both reasonable! > Yes it is a reasonable approach, expecially when bandwidth is an issue and you're expecting high usage. > > Any pointers at all would be appreciated. > HTH, Curt -- "I used to think I was indecisive, but now I'm not so sure."

« previous php.general (#159393) next »