2

My application XMLReader reads XML file from remote location. What would be the maximum file size (in bytes) for me to start reading?

Thanks

if ($file_size > XXX)
{
   exit('Wohooo that is a massive file to handle for me. Chop it up please');
}
BentCoder
  • 12,257
  • 22
  • 93
  • 165

1 Answers1

1

Why do you care about the max_file size? using something like fgets you can read it one line at a time, or something like fread you can set how much to get at a time.

Using either one of these, you can easily control how much resources your script will use if you keep the memory under control.

If you are worried about chewing off too much system resource with your script, this is a fantastic read about how to better utilize memory vs CPU cycles on your server. I normally opt for unset() btw, seem to find that it gets better results.

Community
  • 1
  • 1
Fluffeh
  • 33,228
  • 16
  • 67
  • 80
  • I cannot remember the link to give reference but cURL is preferred over fgets() and fread() for checking if the remote file exist or not, also checking file size of them. – BentCoder Jul 30 '12 at 13:12
  • @MaxMax From what I can [see](http://www.php.net/manual/en/function.curl-multi-getcontent.php) though, it doesn't have the option to only get a selected amount of data at a time. They will return the entire thing into one string. That might not work so well if the file size is large. With both the suggestions I made, the code can handle say 10Kb at a time, or pick a few hundred rows. Even if the file is very large, server resources can be managed easily. – Fluffeh Jul 30 '12 at 13:20
  • 1
    I'm not using `curl_multi_getcontent()` though. I use [this exaple](http://stackoverflow.com/questions/2602612/php-remote-file-size-without-downloading-file) – BentCoder Jul 30 '12 at 20:15