Home > PHP Framework > Laravel > body text

Laravel uses Redis to share Session (detailed code explanation)

藏色散人
Release: 2020-07-13 16:20:18
forward
3727 people have browsed it

Laravel uses Redis to share Session (detailed code explanation)

1. When the number of visits to the system increases, using Redis to save the Session can improve the performance of the system and also facilitate multi-machine load. Share Session

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

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

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

'connection' => 'session',
Copy after login

3. Modify env and use redis to access Sessoin

SESSION_DRIVER=redis
Copy after login

Access the system now. The session has been saved using redis. About 15% performance improvement (current project)

2. Redis access configuration. In order to use other servers to access redis, you need to configure redis remote access

1 .Open /etc/redis.conf and modify the bind information. For example, the current server LAN IP is 10.0.0.2

bind 127.0.0.1 10.0.0.2
Copy after login

2. Modify protected-mode

protected-mode no
Copy after login

3. Reload the redis configuration

service redis-server reload
Copy after login

4. Register and check whether iptable has opened port 6379 for access

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

5. Other servers modify env

REDIS_HOST=10.0.0.2
Copy after login

Now other servers can access the redis server.

For more technical articles related to the laravel framework, please visit the laravel tutorial column!

php Chinese network learning topic: php session (including pictures, videos, cases)

The above is the detailed content of Laravel uses Redis to share Session (detailed code explanation). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!