php - Laravel problem with cache file when deploy to heroku
Get the solution ↓↓↓My application is using laravel 8. I deploy it from github to heroku and i want to cache config of application like the way i use in localhost by using php artisan config/route/view/event:cache. The problem is i dont know where to run these commands and if i can create cache files in my app then heroku will delete them after specific time because they are not permanently file deployed from github. Anyone know how to deal with this pls tell me what to do. Thank you!
P/s: i tried to do like the link below but it didnt create any cache file in my app. https://dev.to/autoidle/laravel-deployment-optimization-on-heroku-1hkc
[new update] the way to cache config follow the link above does create cache file. The only thing i care right now is will heroku remove those cache files after a specific time or not. i will wait and update info later (or anyone know the answer pls tell me) Thank you!
Answer
Solution:
[new update] You can follow the link below and do exactly the same but you need to fix the part of Procfile from composer warmup to composer run-script warmup. That will solve the problem in this thread. https://dev.to/autoidle/laravel-deployment-optimization-on-heroku-1hkc
composer.json:
"scripts": {
...
"warmup": [
"@php artisan config:cache",
"@php artisan route:cache",
"@php artisan view:cache"
]
},
Procfile:
web: composer run-script warmup && heroku-php-apache2
Answer
Solution:
Heroku uses an ephemeral filesystem, that means that any changes to the filesystem whilst the dyno is running only last until that dyno is shut down or restarted. Each dyno boots with a clean copy of the filesystem from the most recent deploy. This is similar to how many container-based systems, such as Docker, operate.
The solution to your problem is to use Redis as cache (and also for session, queue, ...)
Add to your Heroku environments:
CACHE_DRIVER=redis
composer require ext-json
Install Redis as add-on for example: https://elements.heroku.com/addons/heroku-redis
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: a non well formed numeric value encountered
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.