Which is better Redis on Lumen or Laravel? - laravel

I just learned about Redis and I want to try create a scalable Web Application, to achieve this I'm going to use Laravel as the main and Lumen as the microservice (API). So after I learned about Redis, I want to add it to my project, but I confused and tried to get a explanation from google, but no luck. I still confused after read a lot of tutorials.
My questions are:
Should I make it separated from the server? (because I saw it on
Docker, redis will be on separated container)
Should I append it to the Laravel? (because it's the main)
Thank you

To connect redis to Laravel see laravel official document
To connect lumen to redis see this links:
lumen doc for cache
lumen doc for queue
You can put your redis in any server you want and connect it to laravel or lumen with (in your .env file):
REDIS_Host="yout server"
REDIS_port="port of your server to connect redis"
REDIS_password="password which set in redis"
NOte: You are not force append redis to laravel if you need it in lumen just!

First of all, Redis is an in-memory data structure that is used as a database, cache and message broker What is Redis. It is similar to the database (DB) you would connect to but not something you can include in your app.
It sits somewhere, running as a daemon and you connect to it for the purposes of caching or message brokering, etc.
Now that you know you cannot append to it, do you want faster caching or session management? do you have the resources to support it? If yes, then you should connect to Redis.
Kindly take notice of something however, if you are going to run both Lumen and Laravel on the same system, you have to make certain changes to both environment files for the two applications.
eg. .env (Laravel app), you can change things like REDIS_HOST to REDIS_HOST_LARAVEL while you maintain it for .env (Lumen app). Another example is DB_HOST to something else like MY_DB_HOST and change them accordingly in the config/ files.
For some reason they can behave weird running to Lumen or Laravel apps on the same server connecting to Redis for cache or session management.

Related

Running a Laravel app in Fargate: which folders do I need to persist?

I am going to run a containerized Laravel app on AWS Fargate.
Since the container storage is ephemeral, I wonder if there are some part of the app that I need to store in a stateful storage (EFS).
I'd imagine I should store the session data in storage/framework/sessions.
Should I also keep these?
storage/framework/cache
storage/framework/views
anything else? What is the best practice?
EDIT: I'm going to save the sessions in the DB
yes, keep the session data. You can use the database driver for that. There's no need to save the cache. You may or may not want to save the logs (storage/logs/laravel.log) depending on your use case.

Laravel app not working after deploying on Heroku

I have a Laravel app working perfectly on my localhost, but when I deploy it on Heroku cloud, it gives the following error,
ErrorException:
file_put_contents(/tmp/build_a3cd0b04/storage/framework/sessions/YZFia5zZhnq2Lz2jZmdD9uZKjiQUU9KnMmRU0oad):
Failed to open stream: No such file or directory
I have tried changing permissions of the storage folder, clearing cache, etc., but nothing works. Any ideas, please?
It looks like you are using the file driver. That isn't a very good choice on Heroku due to its ephemeral filesystem. It won't scale horizontally and sessions will be lost unpredictably (whenever your dyno restarts, which happens at least once per day).
I suggest using the Redis, Memcached, or database driver.
If you already have aa database, that driver is likely easiest. You can use the session:table Artisan command to generate a database migration for holding session data. Commit that migration, update your config/session.php accordingly, redeploy, and run your migrations.
I suspect the cookie driver would also work. Basically, you can use anything but the file driver (or the toy array driver).

Laravel Application session expires on AWS ELB

I have a Laravel application deployed on AWS Elastic Beanstalk with a classic load balancer. Somehow the user sessions expire at irregular times. Sometimes it expires right after logging in and most times few minutes after logging in. On some occasions to, it takes hours to expire. but on localhost, this doesn't happen.
I have configured my session duration in my Laravel application to 10hours and this works perfectly on localhost but somehow it doesn't work on AWS ELB.
I'm suspecting that AWS resets the app sessions a number of times within a day. If that's the case, how do I overcome this? If that's not the case, then what might be causing this?
I'm posting the answer here just so anyone runs into the same problem. What happens with AWS servers is that, They kind of redeploy your codes a couple of times a day and this clears all newly created files and uploaded files in your project. That's why you have to use a cloud storage if you want to store files and the same thing happens with sessions.
By default laravel saves sessions in a file and whenever AWS redeploy your code, it wipes all current session because it deletes the session file. The solution is store the sessions anywhere but the file. So i used my database to store sessions and cache. You can do that by
Going to the config/session.php and changing the driver to database
After run
php artisan session:table
php artisan migrate
These will create the sessions table in the database for you and that should fix the AWS problem. Just like #arun-a said in short. you can checkout the sessions docs for more info.
If you are using load balancer, you have to keep session as centralized to access over multiple servers. So use session driver as database instead of file and do related migration. Refer here.

laravel lvs and create *blade.php by java service

I now have nginx clusters, many php server, I want java services to manage laravel template file, database storage, and then generate php files, stored in the ceph server configuration template path laravel for path ceph service, I tried it, Could not load, but through shared folders or FTP way to work normally
Database management laravel template file, dynamically generated, stored in the resource server ceph
How should I do? Is there any way? If not, the only choice ftp
There are several packages that allow the storage of Laravel templates in the database.
Here is one: https://github.com/delatbabel/viewpages

Databaseless Laravel +Codeception - turn off database connection completely?

I am building an API calling app which needs no database. In trying to register a new class, I updated my composer and it updated lots of packages including Laravel (now 4.1.25). Now when I run my tests (Codeception) they break as its asking for a database connection. I can't see in the Laravel config options or looking at db connection code how to turn off database completely so it does not look for a connection.

Resources