Consistently use either is_file() or file_exists()

Created on 7 November 2011, over 13 years ago
Updated 16 January 2025, 3 months ago

See discussion in #655190: Allow hook_install_tasks() to be called from a profile's .install file (or document that it can't be) β†’ for background.

Also see #752730: Remove file_exists() during bootstrap β†’ which is trying to remove some unnecessary file_exists() + require_once() from bootstrap to replace them with just include_once() - that would remove most file_exists() in the critical path altogether.

πŸ“Œ Task
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

base system

Created by

πŸ‡¬πŸ‡§United Kingdom catch

Live updates comments and jobs are added and updated live.
  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

  • stale-issue-cleanup

    To track issues in the developing policy for closing stale issues, [Policy, no patch] closing older issues

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thank you for creating this issue to improve Drupal.

    We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for 8+ years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.

    Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

    Thanks!

  • πŸ‡¬πŸ‡§United Kingdom catch

    I think this is probably still valid, but we only really care about it in the critical path and it's not straightforward when checking for things that might be directories, so we can't enforce it.

    So I think we should change DrupalKernal::findSitePath() to use is_file(), since that runs on every single request to Drupal. And not worry too much about anywhere else. Asset aggregation used to use file_exists() on every request 12 years ago but don't any more.

  • First commit to issue fork.
  • Merge request !11048use is_file and is_dir β†’ (Closed) created by quietone
  • πŸ‡³πŸ‡ΏNew Zealand quietone

    Updated IS a bit and made an MR. Tests are running.

  • πŸ‡³πŸ‡ΏNew Zealand quietone
  • πŸ‡³πŸ‡ΏNew Zealand quietone

    Correct the counts in the issue summary.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    I'm willing to bet this is random and unrelated

     Json Api Functional (Drupal\Tests\jsonapi\Functional\JsonApiFunctional)
         ✘ Read
           ┐
           β”œ Behat\Mink\Exception\ExpectationException: Current response status code is 200, but 503 expected.
           β”‚
    

    Searched DrupalKernel and all instances have been replaced.

    • catch β†’ committed b310d198 on 11.x
      Issue #1333940 by yesct, quietone, pingers, chx, catch: Try to use...
  • πŸ‡¬πŸ‡§United Kingdom catch

    This looks good - changes the usage in the critical path, leaves everything else because it's not a 1-1 swap.

    The performance benefit per-request is not really measurable except with strace, but across billions of requests for every Drupal website for the next decade or so it will probably add up to something.

  • πŸ‡¬πŸ‡§United Kingdom catch
  • πŸ‡©πŸ‡ͺGermany tstoeckler Essen, Germany

    Is it correct that this means settings.php is no longer allowed to be a symlink? If so, would be nice to get a change notice for this. I do find that particular setup to be useful for local development, i.e. I have a generic settings.php that sets up e.g. the database name and things like that based on the site name and then (along with the respective webserver config) I can easily "spin up" an additional multi-site by just running mkdir sites/foo; ln -s '../settings.site.php' sites/foo/settings.php; and I'm off to the races. Although slightly less neat, not a big deal to change that setup to copy those files around, but, yeah, would be good to have an actual change notice for that, if that is in fact the case.

  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    If #49 is correct then I think we should roll this back, there are surely numerous hosting setups where settings.php is a symlink and there's no technical reason for this to be disallowed.

  • πŸ‡¬πŸ‡§United Kingdom catch

    @tstoeckler are you asking because this no longer works or just in case? https://www.php.net/manual/en/function.is-file.php resolves symlinks so I would think there should be no change for that use case.

  • πŸ‡©πŸ‡ͺGermany tstoeckler Essen, Germany

    Ahh OK, sorry for the noise in that case. No just noticed this issue and apparently I misread the (ancient) discussion above about is_file() vs. file_exists().

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024