Issue Type: Bug Created: 2009-01-20T01:24:55.000+0000 Last Updated: 2009-04-01T04:34:19.000+0000 Status: Resolved Fix version(s): - 1.7.4 (02/Feb/09)
Reporter: Aleksey Rechinskiy (arech) Assignee: Ben Scholzen (dasprid) Tags: - Zend_Config_Writer
Related issues: Attachments:
This is my first bug-report to ZendFramework project, so first of all, let me thank all ZF-team for developing such a nice free product!
I have recently encountered a following problem with Zend_Config_Writer_Ini: method write() sometimes could fail with exception Zend_Config_Exception('Could not write to file "...), if there are a lot of consecutive config writes within a small period of time (3-5 seconds).
I wrote some code yesterday, that is executed by CRON and can run longer that php timeout allows. To get round that timeout, I've written a code to broke the job into several parts and store the state info into config file with Zend_Config_Writer_Ini. When I tested the code, sending manual http requests, I noticed that sometimes Zend_Config_Writer_Ini->write() was throwing an exception Zend_Config_Exception('Could not write to file "...). I think, it happens, because file_put_contents() function, that is used by Zend_Config_Writer_Ini->write(), does some output buffering and when it processes a lot of consecutive config writes (from different script runs), there are some collisions with file write access, that leads to file_put_contents() failure. When I rewrited the code , that does config file processing, with ordinary fopen-flock(LOCK_EX)-fwrite-fflush-fclose functions, the problem disappeared.
The bug is hard to reproduce - I tried to reproduce it today to test if file_put_contents(,,LOCK_EX) would solve the problem, but I failed - Zend_Config_Writer_Ini worked fine. But this could also mean, that filesystem cache (I use Apache2 on WindowsXP) was relatively fresh that time and able to prevent such collisions.
I think, there are at least two possible solutions: 1) rewrite Zend_Config_Writer_Ini->write() with fopen-flock(LOCK_EX)-fwrite-fflush-fclose functions. It guaranties that the file will be written correctly, or 2) make an option for Zend_Config_Writer_Ini to pass to file_put_contents() function the LOCK_EX flag. In theory, it should also help in such situations, but I failed to test it.
BTW: the bug could also exists in different Zend_Config_Writer_* classes, that uses file_put_contents().
Posted by Ben Scholzen (dasprid) on 2009-01-20T03:42:17.000+0000
The second solution sounds good, I will implement that soon.
Posted by Ben Scholzen (dasprid) on 2009-01-20T04:27:32.000+0000
Fixed with r13708 and merged into 1.7 release branch with r13709.
Posted by Aleksey Rechinskiy (arech) on 2009-01-20T04:43:59.000+0000
I'm impressed how fast the issue was resolved :) Thanks for your work! :)
Posted by old of Satoru Yoshida (email@example.com) on 2009-04-01T04:34:12.000+0000
correct fix version
Have you found an issue?
See the Overview section for more details.