PHP7下如何安裝memcache和memcached擴充
memcache和memcached都是Memcached伺服器的PHP擴充。其中memcache比memcached早出現,所以有些舊的程式碼可能還在用memcache擴充。可以依自己需要,安裝一個即可。這裡兩個的安裝方法都說一下。
Memcached 是高效能的分散式記憶體快取伺服器,而PHP memcache 和 memcached 都是 Memcached 伺服器的 PHP 擴充功能。其中memcache 比 memcached 早出現,所以有些舊的程式碼可能還在用 memcache 擴充。 memcached 後來出現,並且大部分框架都支援 memcached,現在相對較流行。
安裝依賴
首先是memcached,這個擴充功能需要libmemcached 用戶端函式庫,否則會出現如下錯誤
可以透過以下方法安裝checking for libmemcached location… configure: error: memcached support 反射; failed
[root@lnmp lnmp.cn]# yum install libmemcached libmemcached-devel#而memcache模組使用了函數zlib 來支援資料壓縮,因此安裝此模組需要安裝Zlib 模組。否則會出現以下錯誤:
checking for the location of zlib… configure: error: memcache support requires ZLIB. Use –with-zlib-dir=#可以如下方法用yum 來安裝:to specify prefix where ZLIB include and ZLIB include and library are locatedERROR: `/var/tmp/memcache/configure –enable-memcache-session=No' failed
[root@lnmp lnmp.cn]# yum install zlib zlib-devel安裝memcached 擴充功能嘗試用PECL 安裝,memcached 在PECL 上的位址是:https://pecl.php.net/package/memcached
#[root@lnmp lnmp.cn]# pecl install memcachedpecl/ memcached requires PHP (version >= 5.2.0, version #No valid packages foundinstall failed
[root@localhost vagrant]
##提示很明顯,PECL 上的memcached 擴充只支援PHP 5.2 以上,6.00 以下的版本。還未更新到 PHP7。不過還好的是在PECL 的memcached 頁面可以找到他們在github 上的連結:
https://github.com/php-memcached-dev/php-memcached
這上面的程式碼已經有可以支援到PHP7 的分支。這裡將原始碼統一下載到php 原始碼的ext 目錄:
[root@lnmp lnmp.cn]# cd /usr/local/src/php-7.0.8/ext/
[root@lnmp ext]# git clone https://github.com/php-memcached-dev/php-memcached memcached
[root@lnmp ext]# cd memcached/
checkout 到php7 分支:
#用phpize 安裝,我的PHP 是安裝在/usr/local/php7 下[root@lnmp memcached]# git checkout php7
Branch php7 set up to track remote branch php7 from origin.
Switched to a new branch 'php7'
##[root@lnmp memcached]
[root@lnmp memcached]# /usr/local/php7/bin/phpize[root@lnmp memcached]# ./configure –with-php-config=/usr /local/php7/bin/php-config接著make 和make install
[root@lnmp memcached]# make
Installing shared extensions: /usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/[root@lnmp memcached]#[root@lnmp memcached]# make install
#可以看到memcached 已經安裝完成,並且擴充檔案已經放到提示的目錄:[root@lnmp memcached] # ls /usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/
#[root@lnmpmp memcached]memcached.so opcache.a opcache.so
#最後一步在php.ini 中引入memcached.so[root@lnmp memcached]# vim /usr/local/php7/lib/php .ini
加入:
extension=memcached.so
記得reload 一下php-fpm 才能生效
#[root@lnmp memcached]# systemctl reload php-fpm
#開啟phpinfo 頁面,已經看到memcached 擴充功能成功安裝了。
###### 安裝memcache 擴充功能######也嘗試用PECL 來安裝:#########[root@lnmp memcached]# pecl install memcache#########但同樣失敗########/tmp/pear/temp/memcache/memcache.c:40:40: fatal error: ext/standard/php_smart_str. h: No such file or directory###https://pecl.php.net/package /memcache2013年以來為更新。此路不通只能另想辦法,同樣是到 github 上碰碰運氣。搜尋pecl memcachehttps://github.com/search?utf8=✓&q=pecl memcache&type=Repositories&ref=searchresults#其中第一個(https://github.com/websupport -sk/pecl-memcache)就是想要的,而且程式碼已經支援到PHP7,立即下載程式碼編譯:#include "ext/standard/php_smart_str.h"
^
compilation 11ated.
#ERROR: `make' failed看似原因也是PECL 還不支援在PHP7 下安裝memcache 擴充,
[root@lnmp memcached]# cd ../
# [root@lnmp ext]# git clone https://github.com/websupport-sk/pecl-memcache memcache[root@lnmp ext]# cd memcache#用phpize 安裝,步驟和memcached 一模一樣
[root@lnmp memcache]# /usr/local/php7/bin/phpize
#[root@lnmp memcache]# ./configure – with-php-config=/usr/local/php7/bin/php-config[root@lnmp memcache]# make[root@lnmp memcache]# make installInstalling shared extensions: /usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/[root@lnmp memcache]
#類似memcached , 將memcache.so 在php.ini 中引入
#[root@lnmp memcache]# vim /usr/local/php7/lib/php.ini
#加入:
extension=memcache.so
#最後reload php-fpm
[root@lnmp memcache]# systemctl reload php-fpm
大功告成,可以在phpinfo 頁面看到memcahce 和memchaced 都已經成功安裝
推薦學習:php影片教學
以上是PHP7下如何安裝memcache和memcached擴充的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

在Web開發中,我們經常需要使用快取技術來提高網站的效能和回應速度。 Memcache是一種流行的快取技術,它可以快取任何資料類型、支援高並發和高可用性。本文將介紹如何使用PHP開發中的Memcache,並提供具體程式碼範例。一、安裝Memcache要使用Memcache,我們首先需要在伺服器上安裝Memcache擴充。在CentOS作業系統中,可以使用以下命令

解決 PHP 7.0 中插件未顯示已安裝問題的方法:檢查插件配置並啟用插件。重新啟動 PHP 以套用配置變更。檢查插件檔案權限,確保其正確。安裝遺失的依賴項,以確保插件正常運作。如果其他步驟都失敗,則重建 PHP。其他可能原因包括外掛程式版本不相容、載入錯誤版本或 PHP 配置問題。

PHP伺服器環境常見的解決方法包括:確保已安裝正確的PHP版本和已複製相關檔案到模組目錄。暫時或永久停用SELinux。檢查並配置PHP.ini,確保已新增必要的擴充功能和進行正確設定。啟動或重新啟動PHP-FPM服務。檢查DNS設定是否有解析問題。

如何在系統重啟後自動設置unixsocket的權限每次系統重啟後,我們都需要執行以下命令來修改unixsocket的權限:sudo...

在Docker環境中使用PECL安裝擴展時報錯的原因及解決方法在使用Docker環境時,我們常常會遇到一些令人頭疼的問�...

本機環境:redhat6.7系統。 nginx1.12.1,php7.1.0,程式碼使用yii2框架問題:本地的web站需要用到elasticsearch服務。當php使用本機伺服器搭建的elasticsearch時,本地的負載都是正常。當我使用aws的elasticsearchservice服務時,本地伺服器出現負載經常過高的情況。查看nginx和php日誌,發現沒有異常。系統的並發連線數也不高。這時候想到我們老闆跟我講的一個strace診斷工具。偵錯過程:找一個php的子程序idstrace-

PHP開發中如何使用Memcache進行高效率的資料寫入與查詢?隨著網路應用的不斷發展,對於系統效能的要求越來越高。在PHP開發中,為了提高系統的效能和反應速度,我們經常使用各種快取技術。而其中一個常用的快取技術就是Memcache。 Memcache是一種高效能的分散式記憶體物件快取系統,可以用來快取資料庫查詢結果、頁面片段、會話資料等。透過將資料儲存在內存

在PHP開發中,使用Memcache快取系統可以大幅提高資料讀寫的效率。 Memcache是一種基於記憶體的快取系統,它可以將資料緩存在記憶體中,避免頻繁的讀寫資料庫。本文將介紹如何在PHP中使用Memcache進行高效率的資料讀寫操作,並提供具體的程式碼範例。一、安裝和設定Memcache首先,需要在伺服器上安裝Memcache擴充。可以透過
