NoSQL--PHP application Redis, MongoDB

Source: Internet
Author: User
Tags curl redis server

Php-redis

Installing the expansion module

wget Https://codeload.github.com/phpredis/phpredis/zip/develop
MV Develop Phpredis.zip
Unzip Phpredis.zip
CD Phpredis-develop
/usr/local/php/bin/phpize
./configure--with-php-config=/usr/local/php/bin/php-config
Make && make install
Vim/usr/local/php/php.ini//Add a line Extension = redis.so
/usr/local/php/bin/php-m |grep Redis Check for success

Session Sharing for Redis

Add//Not recommended in php.ini
Session.save_handler = "Redis"
Session.save_path = "tcp://127.0.0.1:6379"
or Apache virtual host join//for the lamp architecture
Php_value Session.save_handler "Redis"

Php_value Session.save_path "tcp://127.0.0.1:6379"
or php-fpm.conf the corresponding pool to join//for LNMP architecture
Php_value[session.save_handler] = Redis
Php_value[session.save_path] = "tcp://127.0.0.1:6379"//IP can be replaced with remote Redis server IP
Session test for Redis

vim/usr/local/apache/htdocs/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 ();?>

Test Curl localhost/session.php or Web Access

Output 1443710814<br><br>1443710814<br><br>9jm6nom9ogojedj3pth0iscv22

Connect to Redis
/usr/local/redis/bin/redis-cli
127.0.0.1:6379> keys *//You can list all keys
"Phpredis_session:9jm6nom9ogojedj3pth0iscv22"
127.0.0.1:6379> Get Phpredis_session:9jm6nom9ogojedj3pth0iscv22
"TEST|I:1443710814; test3|i:1443710814; "

Error: If curl is not something plus-I post 500 and the log can't see anything

Fix # display_errors = Off to display_errors = ON//When curl outputs an error, remember to change it back

Php-mongodb

Installing MongoDB Extensions

wget ' Https://codeload.github.com/mongodb/mongo-php-driver/zip/master '-o/usr/local/src/mong_php.zip
cd/usr/local/src/
Unzip Mong_php.zip
CD mongo-php-driver-master/
/usr/local/php/bin/phpize
./configure--with-php-config=/usr/local/php/bin/php-config
Make && make install
Vi/usr/local/php/etc/php.ini//Increase extension = mongo.so
/usr/local/php/bin/php–m
Restart Apache Reload PHP

MongoDB Test Extension

vi/usr/local/apache2/htdocs/1.php//Increase

<?php//Connect to mongodb$m = new Mongoclient (), echo "Connection to database successfully";//Select a database $db = $m->mydb;echo "D Atabase mydb selected ";? >

Test Curl localhost/1.php
----------------------------------------------------------------------------------------------

MongoDB Detailed: http://www.runoob.com/mongodb/mongodb-php.html

Redis Detailed: http://www.runoob.com/redis/redis-tutorial.html

Redis Parameters: http://beibing.blog.51cto.com/10693373/1875638

This article is from the "North Ice--q" blog, please be sure to keep this source http://beibing.blog.51cto.com/10693373/1875636

NoSQL--PHP application Redis, MongoDB

Related Article

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.