Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Down command creates files when using cache driver for maintenance mode #53278

Open
JaZo opened this issue Oct 23, 2024 · 1 comment
Open

Down command creates files when using cache driver for maintenance mode #53278

JaZo opened this issue Oct 23, 2024 · 1 comment

Comments

@JaZo
Copy link
Contributor

JaZo commented Oct 23, 2024

Laravel Version

11.23.5

PHP Version

8.2.24

Database Driver & Version

No response

Description

When you're using the cache based maintenance mode, Laravel still tries to create the framework/maintenance.php file. However, this file does nothing when there's no down-file, which is the case when you're using the cache driver, so basically it is useless.

Example of when this is an issue:

  1. When running a multi server environment, only the server where the down command is ran, will have the maintenance file and the others don't.
  2. When running on a read-only filesystem, the down command will error as the file can't be created.

In both these situations the cache driver should suffice, but currently it has this issue.

N.B. I proposed a solution in #53228, but that wasn't accepted.

Steps To Reproduce

  1. Make sure your cache store isn't file based;
  2. Set the maintenance mode driver to cache;
  3. Make the storage directory read-only;
  4. Run php artisan down;
  5. See that the command fails because it can't create the maintenance file.
@ismaildasci
Copy link

Hey! 👋

You're right—Laravel’s php artisan down command creates the framework/maintenance.php file even in cache-based maintenance mode. This file isn’t really necessary if you’re relying on the cache driver for maintenance status.
Possible Workaround

One option is to create a custom command to enable maintenance mode using only the cache without creating maintenance.php. Here’s an example:

php

use Illuminate\Support\Facades\Cache;
use Illuminate\Console\Command;

class CustomDownCommand extends Command
{
protected $signature = 'custom:down';
protected $description = 'Put the app in maintenance mode (cache-based only)';

public function handle()
{
    Cache::put('maintenance_mode', true, now()->addHours(24)); // 24-hour maintenance mode
    $this->info('Maintenance mode enabled without file.');
}

}

This way, only the cache is used, and maintenance.php won’t be created. Hope this helps! 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
@crynobone @JaZo @ismaildasci and others