Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Removed LOCK_EX for writing Proxy class file #312

wants to merge 1 commit into from

6 participants

Martin Hasoň Alexander radepal Jaka Jančar Joseph Wynn Benjamin Eberlei
Martin Hasoň
hason commented March 29, 2012

LOCK_EX will not work on NFS and many other networked file systems.

Replaces #307

asm89 commented May 03, 2012

@beberlei Did you want to merge this?


Is any chance to merge this ?
Working with Symfony2/doctrine on vagrant with nfs is impossible

Jaka Jančar

Huh, LOCK_EX is there with a reason.

Martin Hasoň
hason commented July 04, 2012

The best solution for configurable file locking is by using stream, e.g. "safe://path_to_proxies".

new Doctrine\ORM\Proxy\ProxyFactory($em, $proxyDir = 'safe://path_to_proxies');

Joseph Wynn

LOCK_EX is not really required, since proxy classes should only be generated manually (except in a dev environment).

Jaka Jančar

Dev environment is actually a pretty good reason: sometimes you have multiple concurrent requests being made (e.g. from an Ajax app), and you don't want one to corrupt another.

However, on further thought and some more testing, LOCK_EX is actually not sufficient: while this prevents a corrupt proxy file from being written to disk, it does not guarantee that a correct one will be read: require() does not use advisory locking.

This is a reason why I am experiencing:

PHP Fatal error:  Class 'Celtra\\Models\\Proxies\\__CG__\\Celtra\\Models\\Account' not found in .../server/vendor/doctrine/orm/lib/Doctrine/ORM/Proxy/ProxyFactory.php on line 102

I guess a new file would have to be written elsewhere and then atomically moved (rename()'d) into place. However, I'm not sure NFS supports overwriting rename().

Can you confirm?

Jaka Jančar

Overwriting rename seems to work on NFS.


Would it be possible to change:

file_put_contents($fileName, $file, LOCK_EX);


$tmpFileName = $fileName . '.' . uniqid("", true);
file_put_contents($tmpFileName, $file);
rename($tmpFileName, $fileName);
Benjamin Eberlei beberlei closed this July 05, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Mar 29, 2012
Martin Hasoň Removed LOCK_EX for writing Proxy class file d61c947
This page is out of date. Refresh to see the latest.
2  lib/Doctrine/ORM/Proxy/ProxyFactory.php
@@ -189,7 +189,7 @@ private function _generateProxyClass(ClassMetadata $class, $fileName, $file)
189 189
             throw ProxyException::proxyDirectoryNotWritable();
190 190
191 191
-        file_put_contents($fileName, $file, LOCK_EX);
+        file_put_contents($fileName, $file);
193 193
194 194
195 195

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.