<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## 概述 PHP APCu(Advanced and Performance Caching User Cache)是一個用于共享內存的緩存系統,它提供了一個用戶緩存機制,可以被PHP應用程序用來緩存數據。APCu是APC(Alternative PHP Cache)的一個分支,專為PHP 5.5及以上版本設計,并且不包含APC的OPcache功能。 ## 特性 1. **共享內存緩存**:APCu使用共享內存來存儲緩存數據,這意味著多個PHP進程可以訪問相同的緩存數據,從而提高性能。 2. **用戶緩存**:與APC的系統緩存不同,APCu專注于用戶緩存。這意味著它主要用于存儲用戶會話數據和應用程序級別的緩存,而不是編譯后的PHP代碼。 3. **易于使用**:APCu提供了一組簡單的函數來存儲和檢索緩存數據。例如,`apcu_store()`、`apcu_fetch()`、`apcu_delete()`等。 4. **性能提升**:通過緩存經常訪問的數據,APCu可以顯著減少數據庫查詢和文件I/O操作,從而提高應用程序的性能。 5. **內存管理**:APCu會自動管理緩存的內存使用,當內存不足時,它會根據需要自動清理舊的緩存數據。 6. **安全性**:APCu的緩存數據是進程隔離的,這意味著不同的PHP進程不能訪問彼此的緩存數據,從而提高了安全性。 7. **配置**:可以通過`php.ini`文件配置APCu的相關參數,例如緩存大小、清理策略等。 ## 安裝 下載源碼包并解壓 ``` wget https://pecl.php.net/get/apcu-5.1.23.tgz tar -zxvf apcu-5.1.23.tgz ``` 編譯 ``` cd apcu-5.1.23 /usr/local/php-7.4/bin/phpize ``` 執行以下命令 ``` ./configure --with-php-config=/usr/local/php-7.4/bin/php-config ``` 可能會報錯 ``` 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... cc checking 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 ``` 查看錯誤日志`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` 這個提示語表示沒有權限操作 解決方案使用`sudo`操作解決問題 ``` sudo ./configure --with-php-config=/usr/local/php-7.4/bin/php-config ``` 編譯安裝 ``` sudo make -j4 sudo make install ``` 如果沒有報錯,查看擴展是否安裝成功 ```ts 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擴展 ``` sudo vim /usr/local/php-7.4/etc/php.ini ``` 增加以下配置 ``` [apcu] extension = apcu.so apc.shm_size = 1024M ``` 校驗配置是否有效 ``` 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 ``` ## 簡單使用 進行讀寫 ``` <?php $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)` 設置值,注意,緩存有值的情況下無法設置值,類比Redis的setnx,類型支持標量、數組、與對象,這一點非常好。 * `apcu_fetch(key)` 取緩存,獲取不到返回false,并發情況下容易返回false 執行 ``` php apcu.php 0.0011260509490967 ``` https://www.cnblogs.com/phpphp/p/18200989 ## Redis壓測對比連接性能 | 方式 | 輪次 | APCu耗時(秒) | Redis耗時(秒) | | --- | --- | --- | --- | | 只讀 | 10000 | 0.011 | 1.162 | | 只寫 | 10000 | 0.012 | 1.062 | | 讀寫,一次new Redis | 10000 | 0.011 | 2.117 | | 讀寫,多次new Redis | 10000 | 0.011 | 3.646 | ~~~php 只讀(APCu): ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看