tomarius's avatar

Blade::render() unlink error

I'm using Blande::render() to generate content for my emails: Blade::render(string: $body, data: $placeHolderData, deleteCachedView: true); but I'm getting a lot of errors like this because I use deleteCachedView: true: unlink(/var/www/html/storage/framework/views/456c7288c355db70f44f3fdca12cd0cd.blade.php): No such file or directory

It works fine when I test it locally but once I moved it to production I'm getting these errors...

If I set deleteCachedView to false am I going to have issues with the cache or filling up: /var/www/html/storage/framework/views/ with data?

I see that is coming from BladeCompiler.php render() (part of Laravel code)

if ($deleteCachedView) {
               unlink($view->getPath());
           }

It will make more sense to have something like this there:

if ($deleteCachedView && file_exists($view->getPath())) {
                unlink($view->getPath());
            }

Been searching the internet but I can't find anyone complaining about this issue, which is very strange

0 likes
7 replies
tisuchi's avatar

@tomarius Maybe you can try this:

if ($deleteCachedView && file_exists($view->getPath())) {
    unlink($view->getPath());
}
Snapey's avatar

There is no data in the cached view, and probably no need to unlink it.

tomarius's avatar

The unlink is because I use deleteCachedView: true and Laravel does it... This is from their Docs

Laravel renders inline Blade templates by writing them to the storage/framework/views directory. If you would like Laravel to remove these temporary files after rendering the Blade template, you may provide the deleteCachedView argument to the method:
megaezz's avatar

Had the same issue now. It happened on production because of race condition. When 2 processes handle one view at the same time, then first process delete rendered view (because of deleteCachedView option) and another process still needs it.

megaezz's avatar

So, the only way I found to avoid this problem is to render string by Blade::compileString + ob_start(), extract(), ob_get_clean().

Please or to participate in this conversation.