Is there a "race condition"?
| From: | Konstantin | Date: | Fri, 07 Feb 2003 11:01:02 +0000 |
| Subject: | Is there a "race condition"? | ||
| Groups: | php.smarty.dev | ||
| Request: | Send a blank email to php-smarty-dev+get-668@lists.php.net to get a copy of this message | ||
Looking into Smarty (2.3.1) code, I see that compiled
template update is not atomic (fopen-flock-fwrite-fclose-touch)
and there is no flock before include of it. Is there flock in PHP
include code?
Theoretically, it seems to me that one process can include
compiled template just after another process discards
its content in fopen (for writing). It means, one request
will receive empty output.
It is possible that parallel processes will compile a template
(in the time between checking mtime and touching). It's not
very bad, but some waste of performance.
We are using PHPA accelerator, and it seems possible that empty
compiled template can be cached. (It really happens with another
caching systems or ftp file uploading).
I'm not the perfect programmer. Can anybody investigate it?
Anyway, if I'm right, the solution seems simple: write to a file
with temporary name and rename it after touching (on linux
renames are atomic).
WBR, Konstantin A. Pelepelin