Page 1 of 1

Help with file pointers

Posted: Sun May 17, 2009 3:42 pm
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?

Re: Help with file pointers

Posted: Mon May 18, 2009 8:54 am
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.

Re: Help with file pointers

Posted: Mon May 18, 2009 9:24 am
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.