Skip to content

Commit ddb3b80

Browse files
authored
Note that file_put_contents is non-atomic
1 parent 7ec7857 commit ddb3b80

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

components/dependency_injection/compilation.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,14 @@ serves at dumping the compiled container::
468468
file_put_contents($file, $dumper->dump());
469469
}
470470

471+
472+
.. tip::
473+
474+
Call to `file_put_contents` is not atomic. When generating container in
475+
a production environment with multiple concurrent requests, use `dumpFile`
476+
from `component-filesystem` instead. This generates file in tmp and moves it
477+
to its destination only once it's fully written to.
478+
471479
``ProjectServiceContainer`` is the default name given to the dumped container
472480
class. However, you can change this with the ``class`` option when you
473481
dump it::
@@ -559,6 +567,11 @@ for these resources and use them as metadata for the cache::
559567

560568
require_once $file;
561569
$container = new MyCachedContainer();
570+
571+
.. note::
572+
573+
Using `$containerConfigCache->write` also makes sure that
574+
the file write operation is atomic.
562575

563576
Now the cached dumped container is used regardless of whether debug mode
564577
is on or not. The difference is that the ``ConfigCache`` is set to debug

0 commit comments

Comments
 (0)