//安装php的memcache扩展 一、使用php自带的pecl安装程序 [[email protected] src]# /usr/local/php/bin/pecl install memcache ... ... ... Build process completed successfully Installing ‘/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/memcache.so‘ install ok: channel://pecl.php.net/memcache-2.2.7 configuration option "php_ini" is not set to php.ini location You should add "extension=memcache.so" to php.ini [[email protected] src]# cp /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/memcache.so /usr/local/php/ext [[email protected] src]# vim /usr/local/php/etc/php.ini ... ... ;extension_dir = "./" /*改为extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"*/ //再添加一行 extension = "memcache.so“ //检验,查看是否有memcache [[email protected] src]# /usr/local/php/bin/php -m //检测php是否连接memcache,下载一个已经写好的脚本 [[email protected] src]# curl www.apelearn.com/study_v2/.memcache.txt >1.php 2>/dev/null //执行 [[email protected] src]# /usr/local/php/bin/php 1.php //执行成功-- 只有当在php.ini中定义了memcache模块才可以执行此脚本 Get key1 value: This is first value<br>Get key1 value: This is replace value<br>Get key2 value: Array ( [0] => aaa [1] => bbb [2] => ccc [3] => ddd ) <br>Get key1 value: <br>Get key2 value: <br>
//memcached实现session共享 一、不管在哪种架构中,都能实现的 [[email protected] ~]# vim /usr/local/php/etc/php.ini //添加 session.save_handler = "memcache" session.save_path = "tcp://127.0.0.1:11211" //如果memcached服务为远程机器,则可将ip改为远程机器的ip //测试 [[email protected] src]# wget http://study.lishiming.net/.mem_se.txt [[email protected] src]# mv .mem_se.txt /usr/local/apache2/htdocs/session.php //因为我们要用curl或浏览器访问此脚本,所以要保证其可以被打开 [[email protected] src]# curl localhost/session.php //查看是否有显示内容,如果没有,查看已经配置好的网站文件test.conf
//--!!如果添加到php.ini不成功,可以添加到apache或nginx对应的php-fpm的配置文件中,见下方配置 //在httpd.conf或者test.conf对应的虚拟主机中的配置语句{LAMP结构} php_value session.save_handler "memcache" php_value session.save_path "tcp://127.0.0.1:11211" //在php-fpm.conf中的pool中添加 {LNMP结构}php_value[session.save_handler] = memcachephp_value[session.save_path] = "tcp://127.0.0.1:11211
时间: 2024-10-02 05:40:31