2

I am in the early stages of building a PHP application, part of which involves using file_get_contents() to fetch large files from a remote server and transfer them to a user. Lets say, for example, the targeted file that is being fetched is 200 mB.

  • Will this process time out if downloading to the server takes too long?
  • If so, is there a way to extend this timeout?
  • Can this file that is being downloaded also be transferred to a user simultaneously, or does the file have to be saved on the server then manually fetched by the user once download has completed?

I am just trying to make sure that I know my options or limitations are before I do much too more.

Thank you for your time.

hakre
  • 193,403
  • 52
  • 435
  • 836
Oliver Spryn
  • 16,871
  • 33
  • 101
  • 195
  • Are you asking about the PHP script timing out because it takes so long to download the file? Or the connection to the remote server timing out because of some network issue? – Alex Howansky Apr 27 '12 at 20:18
  • Sorry, I know networking issues will cause a timeout, but I meant PHP timing out due to the amount of time required to download a large file. – Oliver Spryn Apr 27 '12 at 20:22
  • To control the timeout of the `file_get_contents()` call see this question: http://stackoverflow.com/questions/10236166/does-file-get-contents-have-a-timeout-setting – Simon East Mar 16 '15 at 02:37

2 Answers2

2

Yes, you can use set_time_limit(0) and the max_execution_time directive to cancel the time limit imposed by PHP.

You can open a stream of the file, and transfer it to the user seamlessly.
Read about fopen()

Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
  • Excellent! I'm presuming that `php.ini` can override any settings that I would make using `set_time_limit()`. What settings can I check in `php.ini` to ensure that `0` will indeed remove the timeout completely? – Oliver Spryn Apr 27 '12 at 20:24
2

If not a timeout you may well run into memory issues depending on how your PHP is configured. You can adjust a lot of these settings manually through code without much difficulty.

http://php.net/manual/en/function.ini-set.php

ini_set('memory_limit', '256M');
Ben Roux
  • 7,308
  • 1
  • 18
  • 21