There is a folder /data , in it there are many links to folders mounted via NFS, for example.
/data/2C -> /mnt/nfs/data/2C Three-level sub-folder system, PHP gets the name of the folder, for example. /data/2C/3D/FF and creates it if( !file_exists($folderName)) , via mkdir( $folderName, 0775, true) - the third parameter means that, if necessary, you need to create intermediate subfolders.
I noticed a strange glitch - there are loops of links in cases where the names of the first two levels coincide. For example, when the folder /2C/2C/XX needed instead of the subfolder /2C/2C inside /data/2C/ there appears not a subfolder, but a new link to /mnt/nfs/data/2C - thus, a circular reference is formed.
Is this a nfs bug, PHP mkdir() or my code?
The code is about this, nothing special:
public static function getFolder( $id) { $folder = sprintf( '%s/%s', Config::get( 'mycoolapp.DATA_PATH'), self::hexPath( $id) ); // verify / create the folder if( !file_exists( $folder) && !mkdir( $folder, 0775, TRUE)) { Log::error("Folder creation failed", array( 'folder' => $folder)); } The hexPath() method just somehow makes a hexadecimal string XX/YY/ZZZZ from integer id
Everything works great on hundreds of thousands of folders. The exception is these single glitches when the names of subfolders of neighboring levels match.
ls -ldon problem directories in both directories. Rights to / mnt / nfs / data / * what? Also make sure that you use an absolute path, for example, print the contents of$folderbefore creating it. - 0andriy