Is it okay to run php artisan :clear commands on a production laravel website? [closed]

半世苍凉 提交于 2020-07-21 03:14:30

问题


I have a production Laravel website hosted on a DigitalOcean NGINX server, and every time I git push new updates, I always run the following commands:

php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear

composer dump-autoload

Is this a good practice, or will running these commands on my server cause issues?


回答1:


All the clears except the cache one can be part of your deployment script.

But running php artisan cache:clear in production is super risky and cause unexpected results such as losing all of your critical data.

Let's say your cache driver, queue driver, session driver is redis and they all share the same redis instance(same host). When you execute cache:clear it is going to execute the following method

/**
 * Remove all items from the cache.
 *
 * @return bool
 */
public function flush()
{
    $this->connection()->flushdb();

    return true;
}

What it does is executing the flushdb command of redis. It is going to flush the session of all the users, all the queued jobs, all the cached items, all the broadcast related codes if they are in the same database. Here is the method

Delete all the keys of the currently selected DB. This command never fails.

Edit: If they use the same redis driver + same host but different database then this may not cause side-effect problems but it needs manual configuration of setting different databases for different components.




回答2:


I agree with @Ersoy's answer, but just to add something to the mix

I run these commands on push, rather then using clear, i re-cache the config and route. Although keep in mind, that route:cache doesn't work with all possible routes, refer to the laravel documentation about that.

php artisan config:cache
php artisan route:cache
php artisan view:clear

composer install --no-dev


来源:https://stackoverflow.com/questions/61879288/is-it-okay-to-run-php-artisan-clear-commands-on-a-production-laravel-website

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!