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 Fletcher04 Apr 2025
Managing .gitignore changes
When working with Git, the .gitignore file plays a critical role in controlling which files and folders are tracked by version control. Yet, many developers are unsure when changes to .gitignore take effect and how to manage files that are already being tracked. This uncertainty can lead to...
Andrew Fletcher26 Mar 2025
How to fix the ‘Undefined function t’ error in Drupal 10 or 11 code
Upgrading to Drupal 10.4+ you might have noticed a warning in their code editor stating “Undefined function ‘t’”. While Drupal’s `t()` function remains valid in procedural code, some language analysis tools — such as Intelephense — do not automatically recognise Drupal’s global functions. This...
Andrew Fletcher17 Mar 2025
Upgrading to PHP 8.4 challenges with Drupal contrib modules
The upgrade from PHP 8.3.14 to PHP 8.4.4 presents challenges for Drupal 10.4 websites, particularly when dealing with contributed modules. While Drupal core operates seamlessly, various contrib modules have not yet been updated to accommodate changes introduced in PHP 8.4.x. This has resulted in...