Home > Backend Development > PHP Problem > How to set up redis in php

How to set up redis in php

藏色散人
Release: 2023-03-07 10:34:02
Original
2453 people have browsed it

How to set up redis in php: first install the redis service and PHP redis driver; then open the php.ini file; then add the content as "extension=redis.so"; and finally restart php-fpm or apache.

How to set up redis in php

Recommended: "PHP Video Tutorial" "redis Tutorial"

PHP settings use Redis

Installation

Before starting to use Redis in PHP, we need to ensure that the redis service and PHP redis driver have been installed, and your PHP can be used normally on the machine. Next, let us install the PHP redis driver: The download address is: https://github.com/phpredis/phpredis/releases.

PHP installation redis extension

The following operations need to be completed in the downloaded phpredis directory:

$ wget https://github.com/phpredis/phpredis/archive/3.1.4.tar.gz
$ cd phpredis-3.1.4                      # 进入 phpredis 目录
$ /usr/local/php/bin/phpize              # php安装后的路径
$ ./configure --with-php-config=/usr/local/php/bin/php-config
$ make && make install
Copy after login

Modify the php.ini file

vi /usr/local/php/lib/php.ini
Copy after login

Add the following content:

extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20090626"
extension=redis.so
Copy after login

Restart php-fpm or apache after the installation is complete. Check the phpinfo information and you can see the redis extension.

PHP uses Redis

to connect to the redis service

<?php
    //连接本地的 Redis 服务
   $redis = new Redis();
   $redis->connect(&#39;127.0.0.1&#39;, 6379);
   echo "Connection to server successfully";
         //查看服务是否运行
   echo "Server is running: " . $redis->ping();
?>
Copy after login

Execute the script, the output result is:

Connection to server sucessfully
Server is running: PONG
Copy after login

The above is the detailed content of How to set up redis in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Latest Issues
php redis connection problem
From 1970-01-01 08:00:00
0
0
0
About a small error in the redis manual
From 1970-01-01 08:00:00
0
0
0
python2.7 - django cannot connect to redis
From 1970-01-01 08:00:00
0
0
0
I can't connect to redis using php
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template