idlesign / ist-yii-cfile

CFile provides popular functions to manipulate files both with Yii Framework and without
http://www.yiiframework.com/extension/cfile/
MIT License
57 stars 22 forks source link

CFile fails on downloading large files #16

Closed mrfatguy closed 10 years ago

mrfatguy commented 10 years ago

CFile offers support of mod-xsendfile plugin, if you're using Apache server and have it properly configured to use it. If not, it falls back to old, bad readfile. This core PHP function will fail on files even as small as 100-200 MB, even if you have quite very high maximum memory limit set.

What is the saddest, you may not even notice, that your script (that uses CFile, that uses readfile) fails, because -- due to some stupidity of PHP creators -- on certain server configurations, your file will be downloaded in this case, but instead of real content, it will contains a PHP generated HTML code with "exhausted memory" error message.

You may consider implementing a workaround for this problem, for users, that can't use mod-xsendfile. You have to implement using of file chunking. Here you have my answer on Stack Overflow. Use provided code in place, where CFile extension calls readfile function.

idlesign commented 10 years ago

Let's say it'll be a feature for some day ;) Thank you.

mrfatguy commented 10 years ago

Well... it is your extension and your decision, so I respect it.

However, if someone can't or don't want to use mod-xsendfile then your extension (with readfile) will fail on files as small as 100 MB or even less. That isn't to much in nowadays. So, I would suggest to implement this ASAP, not "some day".

Especially, that I gave you a link to working, tested, ready-to-use code. So this is just a copy-paste job. And you're enhancing your extension with being able to handle files of up to 2 GB of size.

idlesign commented 10 years ago

Let me put it another way: I have no intension on that "copy-paste job" anytime soon, as there are more interesting and urgent things I can apply.

However, this extension is not mine, in a sense that it's been given to the community somewhat four years ago. So if you do consider it ASAP, you're more than welcome to fork the code.

idlesign commented 10 years ago

Per se I don't consider it a good idea to serve large files through PHP, yet for real urge we already have xsend. Closing now.

mrfatguy commented 10 years ago

For your (and others) information:

  1. The mod-xsendfile is Apache module. Most non-Apache webservers will not support this technique and using it makes your code unportable. Using file chunking (based on pure PHP code) makes it portable and usable on any kind of web-server. I understand, that Apache is the most popular webserver, but there are many, many sites and hostings, that simply made usage of other ones (to name Microsoft IIS or xitami as one of many).
  2. Your extension, without file chunking / mod-xsendfile chokes on files like 50 MB in size. In nowadays, when GB of data are sent through websites / PHP, naming 50 MB files "large" is a bit old-fashioned. I don't think, there are many, that finds 50 MB file "large".
  3. Do you have any source or argument to support your claim, that "it isn't a good idea to serve large files through PHP"? I found such claim a bit old-fashioned. Good quality, large-scale, lossless image can have more than 50 MB. Not mentioning archives, videos, etc. How would you like to transfer such files, if not through PHP? FTP? How would you like to build a simple video sharing service, if you consider sending large files through PHP to be wrong?

Once again, going back, to my previous comment. These are mine, private opinions. And this is yours extension. If you find implementation of file chunking not worth, then this is fine with me. I've downloaded copy of your code and managed to extend it with file chunking, spending about 15 minutes on this issue. And I'm fine. End of conversation! :]

idlesign commented 10 years ago

3., 2., 1. Use a webserver capabilities (xsend in flavours is supported by all major players).

Cruiser13 commented 10 years ago

trejder would you mind sharing your implementation if it's done already?

mrfatguy commented 10 years ago

@Cruiser13 Sure thing, but I'm going on a short, one-week vacation and won't have access to my repositories / code before end of it. So, I think you're going to do it yourself earlier! :] It's nothing else, than the code from my Stack Overflow answer, ported to CFile extension (changing some variables).