php - redis
安装扩展模块
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
<?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 或 web访问
输出1443710814<br><br>1443710814<br><br>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 //增加
<?php // 连接到mongodb $m = new MongoClient(); echo "Connection to database successfully"; // 选择一个数据库 $db = $m->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
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。