tags:

views:

100

answers:

2

I'm running a script that makes some changes to the contents of a file then resets its modification time to what it was before. Intermittently, I'll find the following errors in my log:

touch() [function.touch]: Utime failed: Operation not permitted

This on the line immediately after a file_put_contents() call appears to have changed the contents of the file I tried to touch(). There are no errors associated with the file_put_contents() line.

Has anyone had this happen? Can anyone figure out what set of permissions would allow me to write a file but not change its modification time? I'm doing this on Linux.

A: 

It could be possible that the file gets created with wrong permissions. Try to chmod 777 the file just after the file_put_contents and then touch the file.

rossoft
Is the user who is running the php script the owner of the file / parent directory? that could be also another useful check
rossoft
+1  A: 

As rossoft says, PHP is probably not the owner of the file. But setting the permissions to 777 might not be the best solution. I'd preferr:

function touch_file($file) {
    fclose(fopen($file, 'a'));
}

touch_file('/path/to/file');
Björn
I would do that, but I'm trying to use touch with a time in the past.
Jeremy DeGroot