Home > php教程 > PHP开发 > Reasons and solutions for incomplete download of large files from Apache site

Reasons and solutions for incomplete download of large files from Apache site

黄舟
Release: 2016-12-21 11:34:36
Original
2377 people have browsed it

I was testing a JQuery plug-in locally today, but the browser kept prompting that line x of the JQuery file was missing "}".

At first I thought there was a problem with the js file, so I re-downloaded JQuery from the official website, but I still had the same problem. I looked at the code again and found no problems.

So I tested it with Firefox and got the same error. So I used FireBug to check the HTTP requests, and they were all 200, so there was no problem.

But when I looked at the response result of requesting the jquery file, I found that the file was incomplete and only a small part of the original file was returned.

Then use Thunder to download the js file from the requested address. It can be downloaded. The size of the downloaded file is also correct. However, after opening it with an editor, I found that the end of the file is different from the original file, and some codes are missing. It turns out that the file requested back is only part of the original file. Then I downloaded several smaller files and found that there was no problem. However, slightly larger files, such as files over 100KB, were downloaded incomplete. This was the first time I encountered this kind of problem. I had no choice but to use Baidu and Google together to finally find the problem. It turns out to be a configuration problem with Apache. The solution is as follows:

Just change the value after EnableSendfile in the block in Apache's configuration file httpd.conf to Off.
If you don’t have this item, add it yourself: EnableSendfile Off, remember to put it in the block above, otherwise Apache will not start.
If you don’t care, you can try setting the value after EnableMMAP to Off.

Cause analysis:

It turns out that by default, when processing a request and does not need to access the data inside the file (such as sending a static file content), if the operating system supports it, Apache will use sendfile to send the file content Send directly to the client without reading the file. This sendfile mechanism avoids separate read and write operations and buffer allocation. Because it is turned on by default, some operating systems do not have enough support for the sendfile system call. Therefore, it will appear that HTML pages larger than a certain capacity cannot be transmitted. Turning it off does not affect normal use.

About the EnableSendfile command and the EnableMMAP command

EnableSendfile command


Description: Use the sendfile support of the operating system kernel to send files to the client
Syntax: EnableSendfile On|Off
Default value: EnableSendfile On

This directive controls whether httpd can use the operating system kernel's sendfile support to send files to clients. By default, when processing a request that does not require access to the data inside the file (such as sending a static file content), if the operating system supports it, Apache will use sendfile to send the file content directly to the client without reading the file. . Translator's Note: Both Linux2.4/2.6 kernels support this.
This sendfile mechanism avoids separate read and write operations and buffer allocation, but on some platforms or some file systems, it is best to disable this feature to avoid some problems:
Some platforms may have errors that are not detected by the compilation system. Defective sendfile support, especially when running binaries cross-compiled on other platforms on platforms that currently have defective sendfile support.
When IPv6 is enabled on Linux, using sendfile will trigger a TCP checksum offload bug on some network cards.
When Linux is running on Itanium processor, sendfile may not be able to handle files larger than 2GB.
For a DocumentRoot with an NFS file system mounted over the network (such as NFS or SMB), the kernel may not be able to reliably serve network files through its own buffer.
If the above situation occurs, you should disable sendfile:
EnableSendfile Off
For NFS or SMB, this command can be overridden by the setting for the directory:
EnableSendfile Off < /Directory>


EnableMMAP command


Description: Use memory mapping (memory-mapping) to read files in delivery
Syntax: EnableMMAP On|Off
Default value: EnableMMAP On

This directive instructs httpd whether it can use memory mapping if it needs to read the contents of a file during delivery. When handling a request that requires access to data in a file, such as when delivering a file that uses mod_include for server-side analysis, Apache will use memory mapping by default if the operating system supports it.
This memory mapping sometimes brings performance improvements, but in some cases, you may need to disable memory mapping to avoid some operating system problems:
On some multi-processor systems, memory mapping will reduce some httpd performance.
On an NFS-mounted DocumentRoot, if a file has been memory mapped, deleting or truncating the file will cause httpd to crash due to segmentation fault.
During server configuration where you may encounter these problems, you should use the following command to disable memory mapping:
EnableMMAP Off
For folders mounted with NFS, you can individually specify to disable memory mapping:
EnableMMAP Off

The above is the reason and solution for incomplete download of large files from the Apache site. For more related content, please pay attention to the PHP Chinese website (www.php.cn )!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template