chipotlegroove's avatar

Changes in code (views, controllers, etc...) not reflected until dev server restart.

Hey all I've been having this very annoying issue:

After some time working my views and logic just stop changing. I try logging and using dd a page with some error but nothing happens. After I restart the server dd/logging/any other change works but if I do additional changes I need to restart the server again.

Oddly enough in the error page the code preview does show the updated file but the one actually being executed is the old one. Pic related: https://media.discordapp.net/attachments/945425636766396439/1493688112608706661/image.png?ex=69dfe0f5&is=69de8f75&hm=a7a60340c310d1e93559cbd80f0cbf3848e83f246147d42fd71c87c3d40ab15c&=&format=webp&quality=lossless

I tried running optimize:clear but that did nothing.

For views I managed to somewhat fix the issue by manually deleting the cache files in storage/framework/cache but I don't know where such files for php files exist.

I read on an old post that using opcache:clear would fix this but it seems like I don't have this command in my current version.

I am using Laravel 13.4.0, PHP 8.5.5 on CachyOS if that matters.

Anyone got any idea on why this is happening?

0 likes
2 replies
imranbru's avatar

This is classic behavior of PHP loading the compiled files from memory instead of reading your disk changes. Since your error page preview shows the updated code but the execution is using the old logic, it essentially guarantees this is an in-memory caching issue.

OPcache is overly aggressive Run php --ini in your terminal to find out which config file your CLI is using. Open it up and look for your OPcache block. For a local dev environment, OPcache should ideally be disabled, or at the very least, configured to check for file changes instantly.

Make sure your settings look like this:

opcache.enable=1
opcache.enable_cli=1
opcache.validate_timestamps=1 ; This is the crucial one. If set to 0, it never checks for updates.
opcache.revalidate_freq=0     ; Forces it to check on every single request.

Note: Alternatively, just set opcache.enable=0 and opcache.enable_cli=0 for local dev to bypass it entirely.

You're running Laravel Octane If you are serving the application using Laravel Octane (FrankenPHP, Swoole, or RoadRunner), the entire framework is booted into RAM once. Changes to controllers, middleware, or service providers will never reflect until the server restarts.

If this is your stack, you must start the server with the watch flag so it auto-reloads on file saves:

php artisan octane:start --watch

Check that php.ini first. 99% of the time, validate_timestamps got toggled off or you installed a pre-configured PHP package on CachyOS that optimized it for production by default.

chipotlegroove's avatar

Hey, thanks a lot this fixed my issue! It was the opcache thing.

Please or to participate in this conversation.