Skip to main content

If you’re running a website on Drupal 10.x or 11.x, you might encounter a warning like this in your logs:

> "Warning: filemtime(): stat failed for sites/default/files/php/twig/67312f8c6d7ee_paragraph.html.twig_oBJkUYn5Hj1Gltpsh3AXvAcSC/ErOs4_HSnzbWqmYFWDDuM3htp2ANqUUtX84lTbfu2Bg.php in Drupal\Component\PhpStorage\MTimeProtectedFileStorage->checkFile() (line 63 of core/lib/Drupal/Component/PhpStorage/MTimeProtectedFileStorage.php)."

Don’t worry – it’s just Drupal’s way of saying, “Hey, I need a little help finding a cached file!” Essentially, it’s trying to grab a Twig template from the cache, but that particular file isn’t there or is out of reach. Instead of letting this message clutter your logs, here’s how to give Drupal the TLC it needs to move past this hiccup.  Let's remove it so it doesn't obscure more critical issues, and point to underlying performance or configuration problems that could impact your website’s reliability.

 

Resolving the warning and ensuring it doesn’t return

1. Clear Drupal’s cache

Drupal generates cached versions of Twig templates to improve performance, but occasionally these cached files become outdated or removed, leading to warnings like this. Clearing the cache will prompt Drupal to regenerate the necessary files.

If you have command-line access, use Drush to clear the cache:

drush cr

Alternatively, clear the cache from Drupal’s admin interface:

  • Navigate to Admin > Configuration > Development > Performance
  • Select Clear all caches

After clearing the cache, check the logs to see if the warning persists.

 

2. Check file permissions

The warning can also arise if Drupal lacks permission to access files in the `sites/default/files` directory, which is where the Twig cache is stored. Incorrect permissions may prevent the system from reading, writing, or regenerating cache files.

To correct file permissions, you can adjust the following settings:

  • Set permissions on the `sites/default/files` directory to `755` (read, write, and execute for the owner; read and execute for others).
  • Ensure that files inside this directory have permissions of `644` (read and write for the owner, read-only for others).
  • Confirm the web server user (e.g., `www-data` on Ubuntu) is the owner of the `files` directory.

Run the following commands on your server if necessary:

sudo chown -R www-data:www-data sites/default/files
sudo find sites/default/files -type d -exec chmod 755 {} \;
sudo find sites/default/files -type f -exec chmod 644 {} \;

 

3. Verify server disk space

Limited disk space, especially in critical directories, can also lead to issues when Drupal tries to create or access cached files. Ensure you have ample storage in both your primary storage and `/tmp` directory, where PHP often writes temporary files.

Check disk usage with the following command:

df -h

If storage is tight, consider clearing unused files or expanding your storage capacity.

 

4. Manually remove stale Twig cache files

If the warning continues, it may indicate that certain Twig cache files are stale or corrupted. In this case, manually deleting the Twig cache will force Drupal to regenerate the necessary templates.

To clear the Twig cache directly:

rm -rf sites/default/files/php/twig/*

After deleting these files, clear Drupal’s cache once more using Drush or through the admin interface.

 

The wrap

The “filemtime(): stat failed” warning is a common yet manageable issue in Drupal 10 and 11. By following these steps, you can eliminate the warning, enhance site performance, and ensure that Drupal can reliably access and generate cached files. As with all server-side adjustments, always back up important files before making changes. Ensuring Drupal has the necessary access, space, and permissions will support smoother performance and help keep your logs clear of clutter.

Related articles

Andrew Fletcher07 Jan 2025
Resolving Twig syntax errors in Drupal
The release of Drupal 10.4.0 sees stricter validation rules being applied to Twig templates, which can result in unexpected errors after an upgrade. One such issue involves the use of regular expressions within Twig's matches operator, leading to syntax errors that can break template rendering.This...
Andrew Fletcher10 Sep 2024
Resolving PHP GD library issues in Drupal
IntroductionFor a while now, one persistent issue has been bugging me: a warning on Drupal's 'status report' page that reads:GD librarylibrary bundled (2.1.0 compatible)Supported image file formats: GIF, PNG.Unsupported image file formats: JPEG, WEBP.Check the PHP GD installation documentation if...