Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

With reference to: http://stackoverflow.com/questions/12211629/php-file-put-contents-not-truncating-file-in-cifs-mount

We have a Seagate BlackArmor NAS device, which is mounted on our Ubuntu 10.04 server as follows:

mount -t cifs -o defaults,credentials=/etc/smbpass/demo.smbpass,uid=1005,gid=1005,dir_mode=0770,file_mod=0660 //xxx.xxx.xxx.xxx/demo/files /var/www/mysite/src/files/

It seems that any operation that is supposed to truncate files and then insert content into those files on the NAS ends up only replacing the first few bytes of the file (up until the length of the new contents), and then the rest of the previous "old" content is still in the file.

For Example:

Contents of myfile.txt: thisisabigfatpandaonwheelsgoingdownthestreet

Run PHP script with code: file_put_contents('myfile.txt', 'blah');

Contents of myfile.txt: blahisabigfatpandaonwheelsgoingdownthestreet

The expected contents of the file is obviously blah, but that's not the case.

Using PHP's fwrite() after creating a file handle with fopen('filename', 'w'); has the same effect. ftruncate() also does not work properly. Using a shell command such as echo -n "blah" > myfile.txt has the same effect (that's how I know it's not a PHP-specific problem).

My only work-around currently is to delete the files and then create them from scratch, but I'd prefer not to change any code in my application, if possible (we only started using the NAS device recently). I'd rather apply a solution to what seems to be an OS-related/mount-related problem.

Any ideas?

share|improve this question

1 Answer 1

I had the exact same symptoms on a samba setup of my own (Debian 6 x64 with samba 3.5.6.). I finally narrowed it down to the following option causing the exact same behaviour:

large readwrite = no

When set to yes instead (or removed, as yes is the default setting), the issues were gone.

Filed bug reports against Debain and upstream Samba:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=699461
https://bugzilla.samba.org/show_bug.cgi?id=9622

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.