Skip to content

opendir() sporadic failure on Docker-mounted filesystem #19010

Open
@wayne530

Description

@wayne530

Description

Additional details:

  1. Not all paths or files exhibit this behavior
  2. A second immediate call to opendir() succeeds
  3. Other built-ins, like \RecursiveDirectoryIterator that also (presumably) use opendir() 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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions