How Laravel uses Redis to share Session, laravelredis

Source: Internet
Author: User
Tags redis server

How Laravel uses Redis to share Session, laravelredis

1. When the system traffic increases, using Redis to save sessions can improve the system performance and facilitate Session sharing when multiple hosts are loaded.

1. Open config/database. php. Add session connections in redis

  'session' => [    'host' => env('REDIS_HOST', '127.0.0.1'),    'password' => env('REDIS_PASSWORD', null),    'port' => env('REDIS_PORT', 6379),    'database' => 10,  ],

2. Open config/session. php and fill in the above redis connection

'connection' => 'session',

3. Modify env to use redis to access Sessoin

SESSION_DRIVER=redis

Access the system now. You have used redis to save the session. Performance Improvement of approximately 15% (current project)

Ii. redis access configuration. To use other servers to access redis, You need to configure redis remote access.

1. Enable/etc/redis. conf to modify the bind information. For example, the current server lan ip address is 10.0.0.2.

bind 127.0.0.1 10.0.0.2

2. Modify protected-mode

protected-mode no

3. Reload redis Configuration

service redis-server reload

4. Check whether port 6379 is enabled for iptable Registration

iptables -I INPUT -s 10.0.0.2 -p tcp -m state --state NEW -m tcp --dport 6379 -j ACCEPT

5. Modify env on other servers

REDIS_HOST=10.0.0.2

Now other servers can access the redis server.

Summary

The above section describes how Laravel uses Redis to share sessions. I hope it will help you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.