Apache php fail to download file
php download curl: (18) transfer closed with bytes remaining to read
curl error curl: (18) transfer closed with bytes remaining to read
chrome error:
ERR_CONTENT_LENGTH_MISMATCH
some background:
- http://www.media-division.com/the-right-way-to-handle-file-downloads-in-php/
- http://stackoverflow.com/questions/31361107/images-fail-to-load-neterr-content-length-mismatch
- http://stackoverflow.com/questions/5375143/php-readfile-returns-zero-length-file
- the way php send the file
work ok on
- centos 5 modphp 5.1 apache ?
- centos 5 fcgi php 5.3 apache ?
dont work on
- centos 7 fcgi php 5.3 apache ?
- Compress everything except images (zip)
<Location />
- Insert filter
SetOutputFilter DEFLATE
- Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html
- Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
- MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
- Don't compress images
SetEnvIfNoCase Request_URI \ \.(?:gif|jpe?g|png)$ no-gzip dont-vary
- Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary </Location>
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI "\.(?:gif|jpe?g|png)$" no-gzip
ignor ERR_CONTENT_LENGTH_MISMATCH
http://stackoverflow.com/questions/22989556/html5-video-err-content-length-mismatch
תוכן עניינים |
headers analisys
c4
bad
Cache-Control: private Connection: Keep-Alive Content-Description: PHP Generated Data Content-Disposition: attachment; filename=New_Text_Document.txt Content-Length: 38 Content-Type: text/plain; charset=UTF-8 Keep-Alive: timeout=5, max=100 Server: Apache/2.4.6 (CentOS) PHP/5.4.16 X-Powered-By: PHP/5.3.29 ...
c54
good
Cache-Control: private Connection: close Content-Description: PHP Generated Data Content-Disposition: attachment; filename=New_Text_Document.txt Content-Encoding: gzip <<<<<<<<<<<<<<<<<<<<<<<< Content-Type: text/plain Pragma: no-cache Server: Apache/2.2.3 (CentOS) Transfer-Encoding: chunked Vary: Accept-Encoding,User-Agent X-Powered-By: PHP/5.3.27 ...
c54 good
Cache-Control: private Connection: close Content-Description: PHP Generated Data Content-Disposition: attachment; filename=drisut.pdf Content-Encoding: gzip <<<<<<<<<<<<<<<<<<< Content-Type: binary/octet-stream Pragma: no-cache Server: Apache/2.2.3 (CentOS) Transfer-Encoding: chunked Vary: Accept-Encoding,User-Agent X-Powered-By: PHP/5.3.27
c4 good
Cache-Control: private
Connection: Keep-Alive
Content-Description: PHP Generated Data
Content-Disposition: attachment; filename=drisut.pdf
Content-Encoding: gzip
Content-Type: binary/octet-stream
Pragma: no-cache
Server: Apache/2.4.6 (CentOS) PHP/5.4.16
Vary: Accept-Encoding,User-Agent
X-Powered-By: PHP/5.3.29
What happens if you serve content with a different length than the Content-Length header
https://wordpress.org/support/topic/err_content_length_mismatch-when-downloading-pdf
In FF it returns an empty PDF. In IE it asks for permission to download a 265KB PDF, but then the downloaded PDF is empty. In Chrome it just raises an the error of ERR_CONTENT_LENGTH_MISMATCH.
https://gist.github.com/voronianski/791ef517c5392d7ce5fb
php-fpm
php-fpm ERR_CONTENT_LENGTH_MISMATCH apache php-fpm "ERR_CONTENT_LENGTH_MISMATCH"
We're using Apache with PHP in FastCGI Mode (PHP-FPM) and after we removed the Header('Content-Length') stuff in /includes/vb5/frontend/Controller.php it seems to work in Chrome now.. Code:
// sendAsJsonAndCloseConnection Line 295 //Header('Content-Length' ...)
... grep -R --include=*.php "Content-Length" ./
php-fpm
On the advanced custom fields it says that the problem could potentially be with the max_input_vars value in the php.ini file. I increased my value from 1000 to 3000 and that fixed the issue on one of my sites.
Content-Description: PHP Generated Data
Content-Disposition: attachment; filename=drisut.pdf
Content-Length: 342580
grep -R --include=*.php "PHP Generated Data" ./
grep -R --include=*.php "Content-Encoding" ./
chrome ignor ERR_CONTENT_LENGTH_MISMATCH
apache php fcgi SetOutputFilter DEFLATE
You can add zlib.output_compression = On to your php.ini configuration file. This will compress the output regardless of mod_deflate.
http://stackoverflow.com/questions/2835818/how-do-i-enable-mod-deflate-for-php-files
4
down vote accepted
It's been a while since I posted this question - I ended up enabling zlib compression via PHP.ini so zlib compresses PHP output while mod_deflate compresses everything else.
I'm thinking the reason it wasn't working (mod_deflate wasn't compressing PHP output) has to do with PHP running as CGI and not an Apache DSO...
http://serverfault.com/questions/555140/apache-mod-deflate-does-not-compress-php-output