On my server, occasionally, scripts and cache files created by scripts become locked by the PHP process. Once locked they cannot be accessed either via network share, locally on the server or by PHP itself. Refreshing the page results in access denied errors:
Warning: rmdir(C:\inetpub\wwwroot\mdblog\public\..\cache\posts\2012)
[function.rmdir]: Directory not empty in
C:\inetpub\wwwroot\mdblog\public\system\Filesystem.php on line 52
Line 52 is rmdir($dir);
.
The problem is more prevalent after a 'high' amount of disk operations (refreshing a page quickly in succession, deleting many files at once etc). It is a Windows Server 2008 R2 server with IIS7 and PHP 5.3.13 (using FastCGI), running on a VM server, no virus-scanner, with PHP installed using the Web Platform Installer. dxdiag
Doing an iisreset
fixes the problem temporarily. I am writing a static site generation function however which causes this problem to come up every few minutes.
As the error is saying, the folder is not empty, so cannot be erased. Might be because not all temporary files got deleted. Try implemeneting and using a recursive function...
function rrmdir($dir) {
foreach(glob($dir . '/*') as $file) {
if(is_dir($file))
rrmdir($file);
else
unlink($file);
}
rmdir($dir);
}
This function will delete everything inside a folder and then delete it.
Is it possible that your script chdir()-ed to the directory? Under Windows, you cannot delete the current directory of any running process. Sometimes you can get strange messages (like "directory not empty") while the real reason is that there are processes running with that directory as their current.
My idea is that IIS keeps PHP processes alive (because under Windows, starting new processes is heavy-weight operation), and so unused processes in the pool are preventing you from deleting these directories. By restarting IIS, you kill all processes in the pool, making the deletion possible.
Try to chdir() to a default directory at the end of your PHP scripts, and see if it works.