php / php/doc-en

[Bug] file_exists, is_readable and is_writable do not use stat cache

Open
#4,572 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
XML
Stars
596
Forks
890
Avg merge
1d 15h
Merged PRs (30d)
55

Description

Affected page

https://www.php.net/manual/en/function.file-exists.php
https://www.php.net/manual/en/function.is-readable.php
https://www.php.net/manual/en/function.is-writable.php

Issue description

In the notes section of all three links it says the function is using stat cache but it isn't.
When you run on Linux:

strace php --run "echo is_dir('moh123');" 2>&1 | grep moh123
strace php --run "echo file_exists('moh123');" 2>&1 | grep moh123

You will see that is_dir uses newfstatat syscall which indicates that it's using stat cache.
While file_exists uses access syscall which indicates it's not using stat cache.

Steps to reproduce

  1. Create a file called moh123
  2. Run the test script
<?php
while (true)
{
   echo file_exists("moh123") ? 1 : 0;
   sleep(1);
}
  1. Delete file moh123 and you will see that the output changes (because it's not cached).

Suggested fix

Remove stat cache note.

I'm using Debian and PHP 8.2.28

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the notes sections of the file_exists, is_readable, and is_writable manual pages listed in the issue, then run the supplied PHP loop and Linux reproduction if needed to verify the behavior. Done means the stat-cache note is removed or corrected consistently on all three pages, with the documentation still matching the observed behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.