Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSH (FTP) and Web server concurrent file IO

I have a server with Apache.

I have a problem with concurrent read-write operations on one file.

Assume I have index.html file in Apache DocRoot. In browser I can open a read it.

I'm using Eclipse IDE to modify files directly on server through SSH (or FTP). After made some chages to the file I'm uploading it to server. Upload takes some time.

Problem is: if I try to view file in browser WHILE FILE IS UPLOADING uploading hangs and target file becomes blank. It looks like apache and SSH server both trying to access file, SSH to write, Apache to read. Collision breaks everything.

Any ideas how to avoid this? Maybe some SSH server config options or Apache module?

like image 247
s.webbandit Avatar asked Apr 28 '26 02:04

s.webbandit


1 Answers

You need to lock the file first. Do you know what operating system and apache config you use, is it your own system?

Here is a quote from the apache server docs:

EnableMMAP Directive


Description:
Use memory-mapping to read files during delivery 

Syntax:
EnableMMAP On|Off 

Default:
EnableMMAP On 

Context:
server config, virtual host, directory, .htaccess 

Override:
FileInfo 

Status:
Core 

Module:
core 

This directive controls whether the httpd may use memory-mapping if it needs to read the contents of a file during delivery. By default, when the handling of a request requires access to the data within a file -- for example, when delivering a server-parsed file using mod_include -- Apache httpd memory-maps the file if the OS supports it.

This memory-mapping sometimes yields a performance improvement. But in some environments, it is better to disable the memory-mapping to prevent operational problems:
•On some multiprocessor systems, memory-mapping can reduce the performance of the httpd.
•Deleting or truncating a file while httpd has it memory-mapped can cause httpd to crash with a segmentation fault. 

For server configurations that are vulnerable to these problems, you should disable memory-mapping of delivered files by specifying:
EnableMMAP Off

For NFS mounted files, this feature may be disabled explicitly for the offending files by specifying:

  EnableMMAP Off

as your server is crashing, I suspect that you have this option 'set' for the directory your file is in.

Add the

AllowMMAP Off

to the .htaccess file for your directory.

like image 180
Dru Avatar answered Apr 29 '26 15:04

Dru



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!