phpredis - php使用redis作为session的保存工具
在php使用redis作为session的保存工具时,遇到session被清理的问题导致用户没法登陆
请问该如何解决
我使用两种方式来定义session的保存机制
一种是
<code>php</code><code>ini_set('session.save_handler','Redis'); ini_set('session.save_path','tcp://localhost:6379'); </code>
另一种是
<code>session.save_handler = Redis session.save_path = "tcp://localhost:6379" </code>
在php5.3.28和5.5.10下均不能正常使用session
但是都不能用,请问各位大侠如何解决
ps
@woshicixide 说我写的不详细 那么我就将所有的步骤写一遍
首先是开启redis 使用脚本
redis-server.exe redis.conf
命令运行redis服务器
然后在php.ini中修改session.save_handler 为redissession.save_handler = Redis
然后在php.ini中修改session.save_path 为 "tcp://localhost:6379"session.save_path = "tcp://localhost:6379"
然后重启Apache服务,重载php.ini
打开登陆页面http://localhost/login.php 输入用户名密码 登陆
浏览器自动跳转到登录成功页面,然后自动返回到登陆页ps 在loginaction.php中将登陆的userid写入到session中来判断是否登陆
回复内容:
在php使用redis作为session的保存工具时,遇到session被清理的问题导致用户没法登陆
请问该如何解决
我使用两种方式来定义session的保存机制
一种是
<code>php</code><code>ini_set('session.save_handler','Redis'); ini_set('session.save_path','tcp://localhost:6379'); </code>
另一种是
<code>session.save_handler = Redis session.save_path = "tcp://localhost:6379" </code>
在php5.3.28和5.5.10下均不能正常使用session
但是都不能用,请问各位大侠如何解决
ps
@woshicixide 说我写的不详细 那么我就将所有的步骤写一遍
首先是开启redis 使用脚本
redis-server.exe redis.conf
命令运行redis服务器
然后在php.ini中修改session.save_handler 为redissession.save_handler = Redis
然后在php.ini中修改session.save_path 为 "tcp://localhost:6379"session.save_path = "tcp://localhost:6379"
然后重启Apache服务,重载php.ini
打开登陆页面http://localhost/login.php 输入用户名密码 登陆
浏览器自动跳转到登录成功页面,然后自动返回到登陆页ps 在loginaction.php中将登陆的userid写入到session中来判断是否登陆
我感觉是你的配置有问题吧,我贴一下我的配置。
[Session]
; Handler used to store/retrieve data.
; http://php.net/session.save-handler
session.save_handler = redis
session.save_path = "tcp://xx.xx.xx.xx:6789?persistent=1&timeout=3&database=11&auth=d9cxa2xx67f2xxxxxxxxxxxx58exx5xfxd29"
也不知道你的redis起起来了没,亦不知你的web服务器是否也启动了,有没有异常。redis扩展呢?
楼主的问题问的太大了,就好象用户在问为什么我这个网站打不开,楼主至少把提示什么错误、你是怎么调用的等等这种东西写出来
先确定下你的redis是否需要账号密码,再试下把php配置里面的localhost改成127.0.0.1
其实我比较喜欢使用memcahced 来存储session这类数据!
原因如下:
1.无需设置密码
2.数据结构简单,且响应速度很快
3.做分布式很方便,一台机器专门放session,做共享

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The future of PHP will be achieved by adapting to new technology trends and introducing innovative features: 1) Adapting to cloud computing, containerization and microservice architectures, supporting Docker and Kubernetes; 2) introducing JIT compilers and enumeration types to improve performance and data processing efficiency; 3) Continuously optimize performance and promote best practices.

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

Redis cluster mode deploys Redis instances to multiple servers through sharding, improving scalability and availability. The construction steps are as follows: Create odd Redis instances with different ports; Create 3 sentinel instances, monitor Redis instances and failover; configure sentinel configuration files, add monitoring Redis instance information and failover settings; configure Redis instance configuration files, enable cluster mode and specify the cluster information file path; create nodes.conf file, containing information of each Redis instance; start the cluster, execute the create command to create a cluster and specify the number of replicas; log in to the cluster to execute the CLUSTER INFO command to verify the cluster status; make

PHP is not dying, but constantly adapting and evolving. 1) PHP has undergone multiple version iterations since 1994 to adapt to new technology trends. 2) It is currently widely used in e-commerce, content management systems and other fields. 3) PHP8 introduces JIT compiler and other functions to improve performance and modernization. 4) Use OPcache and follow PSR-12 standards to optimize performance and code quality.

Using the Redis directive requires the following steps: Open the Redis client. Enter the command (verb key value). Provides the required parameters (varies from instruction to instruction). Press Enter to execute the command. Redis returns a response indicating the result of the operation (usually OK or -ERR).

The steps to start a Redis server include: Install Redis according to the operating system. Start the Redis service via redis-server (Linux/macOS) or redis-server.exe (Windows). Use the redis-cli ping (Linux/macOS) or redis-cli.exe ping (Windows) command to check the service status. Use a Redis client, such as redis-cli, Python, or Node.js, to access the server.

Using Redis to lock operations requires obtaining the lock through the SETNX command, and then using the EXPIRE command to set the expiration time. The specific steps are: (1) Use the SETNX command to try to set a key-value pair; (2) Use the EXPIRE command to set the expiration time for the lock; (3) Use the DEL command to delete the lock when the lock is no longer needed.

How to clear Redis data: Use the FLUSHALL command to clear all key values. Use the FLUSHDB command to clear the key value of the currently selected database. Use SELECT to switch databases, and then use FLUSHDB to clear multiple databases. Use the DEL command to delete a specific key. Use the redis-cli tool to clear the data.
