1. Report an error in PHP 7.4: mkdir(): file exists. as shown in Figure 1

if (!file_exists($prefix.DIRECTORY_SEPARATOR.$currentFolder)) {
mkdir($currentFolder, 0755);
chmod($currentFolder, 0755);
}
2. However, in the code implementation, it is first judged that the directory does not exist before executing mkdir(). But at the time of execution, the directory already exists. It should be a problem caused by request concurrency.
3. Reproduce this error in the local environment
$currentFolder = 'E:/wwwroot/currentFolder';
mkdir($currentFolder, 0755);
chmod($currentFolder, 0755);
4. During the first run, no errors were reported, and the directory: e:/wwwroot/currentfolder was successfully created. as shown in Figure 2

5. During the second run, an error is reported: warning: mkdir(): file exists in e:\wwwroot\phpinfo.php on line 6. as shown in Figure 3

6. Adjust the code implementation, use the error control operator: @ Solve. Test code runs in the local environment.
$currentFolder = 'E:/wwwroot/currentFolder';
@mkdir($currentFolder, 0755);
chmod($currentFolder, 0755);
7. During the third run, there is no error.
8. Delete the directory: e:/wwwroot/currentfolder, run again. No error is reported, directory: e:/wwwroot/currentFolder was successfully created. as shown in Figure 4

9. The final code is implemented as follows
if (!file_exists($prefix.DIRECTORY_SEPARATOR.$currentFolder)) {
@mkdir($currentFolder, 0755);
chmod($currentFolder, 0755);
}
Need long-term technical maintenance or remote troubleshooting?
I am a PHP / Go backend engineer with 15+ years of experience, focused on existing system maintenance, bug fixing, performance optimization, server troubleshooting, WordPress maintenance, and small feature iterations.
If your project is facing any of the following issues, we can start with a small troubleshooting task first:
- ✅ PHP / Laravel / Yii2 legacy systems without active maintenance
- ✅ Go / Gin backend APIs that need troubleshooting or optimization
- ✅ Slow, broken, or unstable WordPress websites
- ✅ Nginx / MySQL / Redis / Linux server issues
- ✅ CDN / Cloudflare / DNS / HTTPS configuration problems
- ✅ Long-term remote technical support or part-time maintenance
More details: About Me & Collaboration
WeChat: 13980074657
Email: shuijingwanwq@gmail.com
Telegram: @shuijingwan
GitHub: https://github.com/shuijingwan

Leave a Reply