PHP使用memcached儲存session資訊

來源:互聯網
上載者:User

標籤:php、session、memcached

文檔資訊:文檔amun文檔版本:Version 1.1修改記錄:2017-05-15系統內容:CentOS 6.5 64 bit需求:環境                                       ip                                      軟體Centos6.5_x64_64                   192.168.200.101               memcached libmemcachedApache使用php支援memcached儲存session資訊**以下apache、php、memcached均使用yum方式安裝,如有特殊需求使用源碼包安裝時,配置方式與此不同 關閉防火牆和SElinux安全機制service iptables stopsetenforce 0 1.安裝部署apache使用系統內建的apache即可修改apache設定檔以支援phpvim /etc/httpd/conf/httpd.conf402 DirectoryIndex index.html index.html.var index.php  添加 啟動apacheservice httpd start 2.安裝php有特殊需求可用源碼包安裝,在此實驗使用yum安裝即可yum -y install php php-devel 3.建立測試頁面,測試apache與php的結合vim /var/www/html/index.php<?phpphpinfo();?>  重啟apache伺服器/etc/init.d/httpd restart 使用瀏覽器訪問http://192.168.200.101,出現以下頁面                              4.安裝部署memcached使用yum方式安裝yum -y install memcached #安裝完成後執行: memcached -h #出現memcached協助資訊說明安裝成功  Memcached的配置資訊:#檔案中內容如下,按需要修改vim /etc/sysconfig/memcached PORT="11211"              #連接埠 USER="root"                 #使用者名稱  //將memcached使用者修改為rootMAXCONN="1024"            #最大串連數 CACHESIZE="64"         #記憶體大小 OPTIONS=""                 #附加參數  5.安裝php支援memcached模組需要安裝libmemcached用戶端庫,php的擴充memcached模組,因為該擴充是依賴libmemcached的API 5.1安裝libmemcached用戶端庫tar xf libmemcached-1.0.18.tar.gzcd libmemcached-1.0.18./configure -prefix=/usr/local/libmemcached-with-memcachedmake && make install 5.2安裝php的擴充memcached模組tar xf memcached-2.2.0.tgz cd memcached-2.2.0 /usr/bin/phpize  //先使用phpize命令產生一個configure檔案./configure -enable-memcached -with-php-config=/usr/bin/php-config-with-zlib-dir -with-libmemcached-dir=/usr/local/libmemcached-prefix=/usr/local/phpmemcached --disable-memcached-saslmake && make install 記錄下安裝成功後的提示,類似於:Installing sharedextensions:     /usr/lib64/php/modules/表示安裝成功 5.3增加擴充extension設定檔vim /etc/php.d/memcached.ini    //此設定檔需要手動建立extension=memcached.so 執行php -m命令查看是否載入了memcached模組6.啟動apache和memcachedservice httpd restart //重啟apache服務 /usr/bin/memcached -u root -m 512M -n 10 -f 2 -d -vvv -c 512 >> /opt/memcached.log2>&1      //啟動memcached服務  6.1安裝telnet服務測試memcached服務是否正常yum–y install telnettelnetlocalhost 11211   或者 直接輸入本機IP加連接埠查看在/opt/memcached.log 的日誌7.建立測試頁,測試php是否支援memcached讀取session資訊vim /var/www/html/memcached.php<?phpsession_start();if(!isset($_SESSION[‘test‘])) {$_SESSION[‘test‘] = time();}print$_SESSION[‘test‘];print"<br><br>";print"Session ID: " .session_id();?> 使用瀏覽器訪問http://192.168.200.101/memcached.php,出現以下頁面;

本文出自 “微涼清風的部落格” 部落格,請務必保留此出處http://amunlinux.blog.51cto.com/13112118/1945980

PHP使用memcached儲存session資訊

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.