Re: Crashes in lex_scan at Zend/zend_language_scanner.c / BUG #52752
| From: | Patrick Schaaf | Date: | Fri, 21 Dec 2012 10:23:31 +0000 |
| Subject: | Re: Crashes in lex_scan at Zend/zend_language_scanner.c / BUG #52752 | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-64410@lists.php.net to get a copy of this message | ||
> I understood you correctly using temp file and then rename should fix
> that? Like this?
>
>> file_put_contents('test.tpl.tmp', "<?php
>> #".str_repeat('A',
> mt_rand(4000, 5000))." ?>\n", LOCK_EX);
> rename('test.tpl.tmp','test.tpl');
Exactly!
You could also do it like this:
$tmpname = 'test.tpl.tmp.'.posix_getpid();
file_put_contents($tmpname, '....');
rename($tmpname, 'test.tpl');
That way - adding the process ID to the temporary filename - does not run into
the danger of two processes changing the file at the same time. The LOCK_EX
should handle that case, too, but I usually go for the "appended PID" approach
and don't worry about file locking at all.
best regards
Patrick