Hi tadpubco;
This is Autoptimize not being able to write files to it’s cache directory. Is this systematic, or occasionally? Are there any files in /wp-content/cache/autoptimize?
frank
Hi–There are files in the autoptimize folder. It happens regularly. I had errors throughout the day yesterday and Saturday, when I installed the plugin. I didn’t have any errors overnight so no errors this morning.
And are the file(s) mentioned in (one off) the errors (e.g. autoptimize_d41d8cd98f00b204e9800998ecf8427e.js) is in the cache-dir?
No idea how to solve this I’m afraid; Autoptimize uses pretty plain PHP to write out the cached files;
file_put_contents($this->cachedir.$this->filename,$code);
If that works once, it should really always work, unless somehow something else (at the level of operating system) is -randomly?- preventing writes in some cases.
Hi–More errors this morning so I checked to see if one is in the cache file. One file in the error log is in the cache file but the file size is 0.
really weird; if the file is there with file size 0, it means that file_put_contents succeeded in creating the file, but not in writing to it.
So afraid I’m in the dark here, no idea how to solve this, sorry :-/
Hmm, could you check the filesystem rights on the autoptimize-directory and of a file which has and one which does not have content in it?
Hi–Both (one with and one without content) have the file permissions of 644.
Just for the heck of it, I did uninstall and re-install but the errors are still happening.
Well, permissions are OK, so file_put_contents() should be able to write to both. The only thing I can think of are concurrency problems, i.e. when the same file is written to simultaneously multiple times.
If you’re willing to do so, you could try a small code change (based on above hunch) to see if it solves the problem (or if it makes it worse). Open up /wp-content/plugins/autoptimize/classes/autoptimizeCache.php and on line 60 replace
}else{
//Write code to cache without doing anything else
file_put_contents($this->cachedir.$this->filename,$code);
}
with
}else{
//Write code to cache without doing anything else
file_put_contents($this->cachedir.$this->filename,$code,LOCK_EX);
}
The added flag tells file_put_contents to lock the file for writing while it is being written to, which should make concurrent writing impossible. This may do away with the warnings.
frank
Hi–I replaced the code but the errors continue.
In that case; this looks very much like a problem outside of AO’s grasp tadpubco. As this is a PHP warning (and not an error) and as there are files in cache/autoptimize, you could -if your site works, from a visitor point of view- consider ignoring the warnings.
Hi–That’s good to know–I had wondered if I could continue to use. I just love your plugin.
And, there is good news: The fix did decrease the number of errors significantly. I’m still getting them but not nearly as many as I was.
Thanks so much for all your help!