Open
Description
Description
Additional details:
- Not all paths or files exhibit this behavior
- A second immediate call to
opendir()
succeeds - Other built-ins, like
\RecursiveDirectoryIterator
that also (presumably) useopendir()
also fail on the first attempt while a second immediate call succeeds
The following code:
<?php
$directory = 'some/relative/path/to/a/directory';
var_dump(opendir($directory));
var_dump(opendir($directory));
Resulted in this output:
WARNING opendir(some/relative/path/to/a/directory): Failed to open directory: No such file or directory in test.php.
bool(false)
resource(12345) of type (stream)
But I expected this output instead:
resource(12345) of type (stream)
resource(12346) of type (stream)
To confirm it is filesystem dependent, running the same code on the same path on the host machine does not produce an error. Host machine is running macOS 15.4. Docker Desktop is current as of submitting this issue (v4.42.1). To further try to rule out php involvement, I also tried UNIX commands inside the container that require calling opendir()
, such as find
and these work without issue. Additionally, the following C code works without issues from inside the container:
#include <dirent.h>
#include <stdio.h>
int main() {
DIR *dirp;
dirp = opendir("some/relative/path/to/a/directory");
if (dirp == NULL) {
printf("Error calling opendir()");
return -1;
}
closedir(dirp);
return 0;
}
PHP Version
PHP 8.3.22 (cli) (built: Jun 11 2025 00:56:01) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.22, Copyright (c) Zend Technologies
with Zend OPcache v8.3.22, Copyright (c), by Zend Technologies
Operating System
Debian bookworm (container)