Redis combined with PHP

Source: Internet
Author: User
Tags php script

The installation and configuration of Redis are described earlier, and the last step is to get a quick overview of how Redis integrates with PHP and enables session sharing.


1.Redis Expansion Module Installation

1. Install the Redis extension for PHP first, and the memcached installation is the same.

First you can go pecl.ph p.net     official website Download the installation package, I download here 2.8.21 version
# tar zxf redis-2.8.21.tgz  
# cd redis-2.8.21
#/usr/local/php/ BIN/PHPIZE
#./configure--with-php-config=/usr/local/php/bin/php-config
# make && make installl installation complete

Then modify the php.ini, before I have extension_dir = "./" revision to

Extension_dir = "/usr/local/php/extensions".

Now add a row
Extension= "Redis.so" Save

/usr/local/php/bin/php-m |grep Redis can verify that the expansion module is added successfully.


PHP script test can follow the previous memcached of the same test, not to mention here can look at the previous article-"Memcached combined with PHP"


2.Redis Implementing session Sharing

Join the Apache virtual Host (lamp environment test)

Php_valuesession.save_handler "Redis"

Php_valuesession.save_path "tcp://127.0.0.1:6379"


or php-fpm.conf the corresponding pool (LNMP environment test)

Php_value[session.save_handler] = Redis

Php_value[session.save_path] = "tcp://127.0.0.1:6379"


3.Redis Storage Session Test

Edit a simple php test file first

Vim session.php

#############

<?php

Session_Start ();

if (!isset ($_session[' TEST ')) {

$_session[' TEST ' = time ();

}

$_session[' TEST3 '] = time ();

Print $_session[' TEST '];

print "<br><br>";

Print $_session[' TEST3 '];

print "<br><br>";

Print session_id ();

?>

####################

Curl localhost/session.php

Output similar to 1469333260<BR><BR>1469333260<BR><BR>JAESI8UMMENFQBCNOJVC6935P7

To Connect to Redis: / usr /local/ Redis /bin/ redis-cli

127.0.0.1:6379> keys *//List all keys

"PHPREDIS_SESSION:JAESI8UMMENFQBCNOJVC6935P7"

127.0.0.1:6379> Get PHPREDIS_SESSION:JAESI8UMMENFQBCNOJVC6935P7

"TEST|I:1469333260; test3|i:1469333260; "

You can also test your input with your browser: ip/session.php

Then on the Redis to see if there is more than a page to display the same key,get this key can get the value results and the browser display is also consistent.





This article is from the Linux OPS blog, so be sure to keep this source http://zhumy.blog.51cto.com/11647651/1829316

Redis combined with PHP

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.