Help with file pointers

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shagey36
Forum Newbie
Posts: 1
Joined: Sun May 17, 2009 3:34 pm

Help with file pointers

Post by shagey36 »

I want to download a file from a url and store it on my server. The size of these files range from 1mb to 1gb.
What I want to do is create a couple of file pointers (one for input and one for output) and stream from one to the other.
I can't do this all in one page load because it will timeout and I don't have access to modifying the timeout settings.
I would like to download a piece every time the page refreshes but I can't save the file pointers in the session.
Anybody have any ideas on how I can achieve this?
MeLight
Forum Commoner
Posts: 26
Joined: Sun Apr 19, 2009 12:39 pm
Location: Israel

Re: Help with file pointers

Post by MeLight »

Why not simply keeping track of the files you're copying, and when you do the refresh, first close the file then re-open it using

Code: Select all

fopen("known_file_name.ext", "[b]a[/b]");
where a stands for append, which means your file will not be overwritten when opened, but it will place the file cursor at the end of the file so you can keep writing on.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Help with file pointers

Post by onion2k »

Using a PHP script fired by a browser request is the wrong solution for this sort of problem. Hand off the download to a queuing system that just works through each request by calling a [perl|php|shell|whatever] script that downloads the necessary file and updates a database record or something when it's done.

Something like http://www.rabbitmq.com/ would work well if you don't fancy writing your own queue.
Post Reply