NoSQL--php应用redis、mongodb
php - redis
创新互联专注于企业营销型网站建设、网站重做改版、三原网站定制设计、自适应品牌网站建设、H5建站、成都商城网站开发、集团公司官网建设、外贸网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为三原等各大城市提供网站开发制作服务。
安装扩展模块
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 // 增加一行extension = redis.so
/usr/local/php/bin/php -m |grep redis 检查是否成功
redis的session共享
php.ini中加入 //不建议
session.save_handler = "redis"
session.save_path = "tcp://127.0.0.1:6379"
或者apache虚拟主机加入 //用于LAMP架构中
php_value session.save_handler " redis"
php_value session.save_path " tcp://127.0.0.1:6379"
或者php-fpm.conf对应的pool中加入 //用于LNMP架构
php_value[session.save_handler] = redis
php_value[session.save_path] = " tcp://127.0.0.1:6379 " //ip可换成远端redis服务器ip
redis的session测试
vim /usr/local/apache/htdocs/session.php
"; print $_SESSION['TEST3']; print "
"; print session_id(); ?>
测试curl localhost/session.php 或 web访问
输出1443710814
1443710814
9jm6nom9ogojedj3pth0iscv22
连接redis
/usr/local/redis/bin/redis-cli
127.0.0.1:6379> keys * //可以把所有的key都列出来
"PHPREDIS_SESSION:9jm6nom9ogojedj3pth0iscv22"
127.0.0.1:6379> get PHPREDIS_SESSION:9jm6nom9ogojedj3pth0iscv22
"TEST|i:1443710814;TEST3|i:1443710814;"
error:如果 curl 不出东西加 -I 后报500而且日志中看不出东西
解决# display_errors = Off 改为 display_errors = On //此时 curl 会输出错误之后记得改回去
php - MongoDB
安装mongodb扩展
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 //增加 extension = mongo.so
/usr/local/php/bin/php –m
重启apache重新加载php
mongodb 测试扩展
vi /usr/local/apache2/htdocs/1.php //增加
mydb; echo "Database mydb selected"; ?>
测试curl localhost/1.php
----------------------------------------------------------------------------------------------
mongodb详解:http://www.runoob.com/mongodb/mongodb-php.html
redis详解:http://www.runoob.com/redis/redis-tutorial.html
redis参数:http://beibing.blog.51cto.com/10693373/1875638
网页名称:NoSQL--php应用redis、mongodb
链接地址:http://cdiso.cn/article/jeodsi.html