宅男在线永久免费观看网直播,亚洲欧洲日产国码无码久久99,野花社区在线观看视频,亚洲人交乣女bbw,一本一本久久a久久精品综合不卡

全部
常見問題
產(chǎn)品動態(tài)
精選推薦

PHP源碼編譯安裝APCu擴(kuò)展,利用APCu實(shí)現(xiàn)數(shù)據(jù)緩存

管理 管理 編輯 刪除

概述

PHP APCu(Advanced and Performance Caching User Cache)是一個(gè)用于共享內(nèi)存的緩存系統(tǒng),它提供了一個(gè)用戶緩存機(jī)制,可以被PHP應(yīng)用程序用來緩存數(shù)據(jù)。APCu是APC(Alternative PHP Cache)的一個(gè)分支,專為PHP 5.5及以上版本設(shè)計(jì),并且不包含APC的OPcache功能。

特性

  1. 共享內(nèi)存緩存:APCu使用共享內(nèi)存來存儲緩存數(shù)據(jù),這意味著多個(gè)PHP進(jìn)程可以訪問相同的緩存數(shù)據(jù),從而提高性能。
  2. 用戶緩存:與APC的系統(tǒng)緩存不同,APCu專注于用戶緩存。這意味著它主要用于存儲用戶會話數(shù)據(jù)和應(yīng)用程序級別的緩存,而不是編譯后的PHP代碼。
  3. 易于使用:APCu提供了一組簡單的函數(shù)來存儲和檢索緩存數(shù)據(jù)。例如:apcu_store()、apcu_fetch()、apcu_delete()等。
  4. 性能提升:通過緩存經(jīng)常訪問的數(shù)據(jù),APCu可以顯著減少數(shù)據(jù)庫查詢和文件I/O操作,從而提高應(yīng)用程序的性能。
  5. 內(nèi)存管理:APCu會自動管理緩存的內(nèi)存使用,當(dāng)內(nèi)存不足時(shí),它會根據(jù)需要自動清理舊的緩存數(shù)據(jù)。
  6. 安全性:APCu的緩存數(shù)據(jù)是進(jìn)程隔離的,這意味著不同的PHP進(jìn)程不能訪問彼此的緩存數(shù)據(jù),從而提高了安全性。
  7. 配置:可以通過php.ini文件配置APCu的相關(guān)參數(shù),例如緩存大小、清理策略等。

安裝

下載源碼包并解壓

wget https://pecl.php.net/get/apcu-5.1.23.tgztar -zxvf apcu-5.1.23.tgz

編譯

cd apcu-5.1.23/usr/local/php-7.4/bin/phpize

執(zhí)行以下命令

./configure --with-php-config=/usr/local/php-7.4/bin/php-config

可能會報(bào)錯(cuò)

checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for cc... ccchecking whether the C compiler works... no
configure: error: in `/home/www/build/apcu-5.1.23':
configure: error: C compiler cannot create executables
See `config.log' for more details

查看錯(cuò)誤日志config.log

compilation terminated.
configure:2894: $? = 1
configure:2914: checking whether the C compiler works
configure:2936: cc    conftest.c  >&5
cc1: error: /usr/local/include/x86_64-linux-gnu: Permission denied
configure:2940: $? = 1
configure:2978: result: no
configure: failed program was:
| /* confdefs.h */|
| #define PACKAGE_NAME "" 
| #define PACKAGE_TARNAME ""
| #define PACKAGE_VERSION ""
| #define PACKAGE_STRING ""
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| /* end confdefs.h.  */
|
| int
| main ()
| {
|
|   ;
|   return 0;
| }
configure:2983: error: in `/home/www/build/apcu-5.1.23':
configure:2985: error: C compiler cannot create executables
See `config.log' for more details

可以看出error: /usr/local/include/x86_64-linux-gnu: Permission denied 這個(gè)提示語表示沒有權(quán)限操作

解決方案使用sudo操作解決問題

sudo ./configure --with-php-config=/usr/local/php-7.4/bin/php-config

編譯安裝

sudo make -j4
sudo make install

如果沒有報(bào)錯(cuò),查看擴(kuò)展是否安裝成功

ls -l /usr/local/php-7.4/lib/php/extensions/no-debug-non-zts-20190902/
total 183804
-rwxr-xr-x 1 root root    650472 Jul 24 09:34 apcu.so
-rwxr-xr-x 1 root root   1033840 Mar 17  2021 event.so
-rwxr-xr-x 1 root root    275008 Jul  2 11:01 gmssl.so
-rw-r--r-- 1 root root 131697456 Feb 25  2022 grpc.so
-rwxr-xr-x 1 root root   6252494 Mar 17  2021 opcache.a
-rwxr-xr-x 1 root root   2894784 Mar 17  2021 opcache.so
-rw-r--r-- 1 root root   1274552 Feb 25  2022 protobuf.so
-rwxr-xr-x 1 root root   2215880 Jun 14 19:12 rar.so
-rwxr-xr-x 1 root root    697352 Feb 22  2022 rdkafka.so
-rwxr-xr-x 1 root root   2850040 Mar 17  2021 redis.so
-rwxr-xr-x 1 root root  37484536 May 23 09:58 swoole.so
-rwxr-xr-x 1 root root     24176 May  2 11:38 utils.so
-rwxr-xr-x 1 root root    154120 Apr 21  2023 xhprof.so
-rwxr-xr-x 1 root root    684928 May  2 09:25 zephir_parser.so

配置APCu擴(kuò)展

sudo vim /usr/local/php-7.4/etc/php.ini

增加以下配置

[apcu]
extension = apcu.so
apc.shm_size = 1024M

校驗(yàn)配置是否有效

php -i |grep apcu

apcu
OLDPWD => /home/www/build/apcu-5.1.23/build
PWD => /home/www/build/apcu-5.1.23
$_SERVER['OLDPWD'] => /home/www/build/apcu-5.1.23/build
$_SERVER['PWD'] => /home/www/build/apcu-5.1.23

簡單使用

進(jìn)行讀寫

$start = microtime(true);
for ($i = 0; $i < 10000; $i++) {
    $key = 'apcu' . $i;
    apcu_add($key, $i);
    apcu_fetch($key);
}

echo microtime(true) - $start . PHP_EOL;
  • apcu_add(key, val, ttl) 設(shè)置值,注意,緩存有值的情況下無法設(shè)置值,類比Redis的setnx,類型支持標(biāo)量、數(shù)組、與對象,這一點(diǎn)非常好。
  • apcu_fetch(key) 取緩存,獲取不到返回false,并發(fā)情況下容易返回false 執(zhí)行
php apcu.php 0.0011260509490967

Redis壓測對比連接性能

方式輪次APCu耗時(shí)(秒)Redis耗時(shí)(秒)
只讀100000.0111.162
只寫100000.0121.062
讀寫,一次new Redis100000.0112.117
讀寫,多次new Redis100000.0113.646

總結(jié):以上為快易數(shù)據(jù)中心實(shí)踐結(jié)果,具體性能效果與測試機(jī)器也有一定關(guān)系~


請登錄后查看

快易數(shù)據(jù)中心 最后編輯于2024-07-27 11:07:12

快捷回復(fù)
回復(fù)
回復(fù)
回復(fù)({{post_count}}) {{!is_user ? '我的回復(fù)' :'全部回復(fù)'}}
排序 默認(rèn)正序 回復(fù)倒序 點(diǎn)贊倒序

{{item.user_info.nickname ? item.user_info.nickname : item.user_name}} LV.{{ item.user_info.bbs_level }}

作者 管理員 企業(yè)

{{item.floor}}# 同步到gitee 已同步到gitee {{item.is_suggest == 1? '取消推薦': '推薦'}}
{{item.is_suggest == 1? '取消推薦': '推薦'}}
沙發(fā) 板凳 地板 {{item.floor}}#
{{item.user_info.title || '暫無簡介'}}
附件

{{itemf.name}}

{{item.created_at}}  {{item.ip_address}}
打賞
已打賞¥{{item.reward_price}}
{{item.like_count}}
{{item.showReply ? '取消回復(fù)' : '回復(fù)'}}
刪除
回復(fù)
回復(fù)

{{itemc.user_info.nickname}}

{{itemc.user_name}}

回復(fù) {{itemc.comment_user_info.nickname}}

附件

{{itemf.name}}

{{itemc.created_at}}
打賞
已打賞¥{{itemc.reward_price}}
{{itemc.like_count}}
{{itemc.showReply ? '取消回復(fù)' : '回復(fù)'}}
刪除
回復(fù)
回復(fù)
查看更多
打賞
已打賞¥{{reward_price}}
2297
{{like_count}}
{{collect_count}}
添加回復(fù) ({{post_count}})

相關(guān)推薦

快速安全登錄

使用微信掃碼登錄
{{item.label}} 加精
{{item.label}} {{item.label}} 板塊推薦 常見問題 產(chǎn)品動態(tài) 精選推薦 首頁頭條 首頁動態(tài) 首頁推薦
取 消 確 定
回復(fù)
回復(fù)
問題:
問題自動獲取的帖子內(nèi)容,不準(zhǔn)確時(shí)需要手動修改. [獲取答案]
答案:
提交
bug 需求 取 消 確 定
打賞金額
當(dāng)前余額:¥{{rewardUserInfo.reward_price}}
{{item.price}}元
請輸入 0.1-{{reward_max_price}} 范圍內(nèi)的數(shù)值
打賞成功
¥{{price}}
完成 確認(rèn)打賞

微信登錄/注冊

切換手機(jī)號登錄

{{ bind_phone ? '綁定手機(jī)' : '手機(jī)登錄'}}

{{codeText}}
切換微信登錄/注冊
暫不綁定
CRMEB客服

CRMEB咨詢熱線 咨詢熱線

400-8888-794

微信掃碼咨詢

CRMEB開源商城下載 源碼下載 CRMEB幫助文檔 幫助文檔
返回頂部 返回頂部
CRMEB客服