seblucas / cops

Calibre OPDS (and HTML) PHP Server : web-based light alternative to Calibre content server / Calibre2OPDS to serve ebooks (epub, mobi, pdf, ...)
http://blog.slucas.fr/en/oss/calibre-opds-php-server
GNU General Public License v2.0
1.44k stars 229 forks source link

Issue with large PDF files #333

Closed eskiiom closed 7 years ago

eskiiom commented 7 years ago

Hello, I just found out that when trying to display/download large pdf files (from 150 to 300mb) the cops server says 403 page not authorized. It works with smaller pdf files (few mb) or pdf converted to epub

I checked the config and rights on files and everything is OK

Thank you

seblucas commented 7 years ago

Hi,

If you did not enable X-Accel-Redirect (or something like it) then the download is handled by PHP :

https://github.com/seblucas/cops/blob/master/fetch.php#L119

Depending on PHP version fpassthru may load the full file in memory. One strange thing though is that 403 is returned, don't really know why ?

Could you try with X-SendFile or X-Accel-Redirect ? That should fix your problem.

eskiiom commented 7 years ago

Hi Seb,

thanks for the reply. I tried both options on files config_local.php and config_default.php with no different result. (when X-Accel-Redirect is active it takes a couple of seconds before giving 403 error. When the value is empty or set to X-Sendfile it's almost immediate) Can it be because it is hosted on synology DSM 5.x ? Do I need to restart something in order for the change to be effective ?

Merci !

seblucas commented 7 years ago

If you use DSM then it's Apache -> you should use X-Sendfile. X-Accel-Redirect is only for Nginx.

Depending on where your Calibre directory is installed you may have to tweak $config['calibre_internal_directory']

seblucas commented 7 years ago

I've been reading a little about DSM and X-SendFile and it seems it may need some configuration :

https://github.com/SynoCommunity/spksrc/issues/957

I won't be able to help you with that sorry.

eskiiom commented 7 years ago

Thanks for the update. I've tried the fix proposed in the last link, changed the COPS config to X-Sendfile, restarted the apache service, it's still the same. It works from the internal network anyway.

It may be broken since a long time, but what I suspect is that I mostly used COPS from Moonreader with a VPN, which is seen as internal and doesn't show the error. I only found out recently when try to download a large file while on the move.

Thanks for the help anyway, I'll live with that and download files locally or with a VPN :) (or try to figure out why the behavior is different from inside and outside)

seblucas commented 7 years ago

I see now, it really seems that X-SendFile is not the issue here. I guess DSM has special checks for internal / external access.

I checked on my VPS with Nginx / PHP 5.6 and I can download a 350Mo PDF without any issue.