PHP APC緩衝安裝配置教程

來源:互聯網
上載者:User

最簡單的方法,找到php安裝目錄的pecl

自動安裝

# /usr/local/php/bin/pecl install apc

接下來按提示一步步完成即可

然後配置 /usr/local/php/etc/php.ini  末尾加入

extension=apc.so
 
手動安裝

官網:http://cn2.php.net/manual/zh/book.apc.php
下載:http://pecl.php.net/package/APC 找最新的

下載apc

# wget http://pecl.php.net/get/APC-3.1.13.tgz
# tar -zxvf APC-3.1.13.tgz
# cd APC-3.1.13

產生configure檔案

# /usr/local/php/bin/phpize

 執行configure 並且make && make install

# ./configure --enable-apc --enable-apc-mmap --with-php-config=/usr/local/php/bin/php-config
# make
# make install

拷貝添加SO檔案

# cp /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/apc.so /usr/local/php/lib/php/extensions/apc.so
# chmod 755 /usr/local/php/lib/php/extensions/apc.so

 修改php.ini使之啟動APC模組

# vi /usr/local/php/etc/php.ini
extension_dir = "/usr/local/php/lib/php/extensions"
extension=apc.so
apc.enabled = 1
; apc.cache_by_default = on
; apc.shm_segments = 1
; apc.shm_size = 128
; apc.ttl = 7200
; apc.user_ttl = 7200
; apc.num_files_hint = 1024
; apc.write_lock = On
; apc.gc_ttl=3600
; apc.ttl=0
; apc.mmap_file_mask=/tmp/apc.XXXXXX

 重啟apache

# service httpd restart
 
使用APC

test.php

<?php
print_r(apc_cache_info());

注意 在瀏覽器看會不是很友好,可以查看網頁原始碼就看到很清晰

Array
(
    [num_slots] => 1031
    [ttl] => 0
    [num_hits] => 3
    [num_misses] => 1
    [num_inserts] => 1
    [expunges] => 0
    [start_time] => 1398341530
    [mem_size] => 4240
    [num_entries] => 1
    [file_upload_progress] => 1
    [memory_type] => mmap
    [locking_type] => pthread mutex Locks
    [cache_list] => Array
        (
            [0] => Array
                (
                    [type] => file
                    [device] => 64768
                    [inode] => 1179758
                    [filename] => /data/www/www.111cn.net /test.php
                    [num_hits] => 3
                    [mtime] => 1398341609
                    [creation_time] => 1398341617
                    [deletion_time] => 0
                    [access_time] => 1398341630
                    [ref_count] => 1
                    [mem_size] => 4240
                )
 
        )
 
    [deleted_list] => Array
        (
        )
 
    [slot_distribution] => Array
        (
            [109] => 1
        )
 
)

多次點擊,可以發現 num_hits  在變化,說明快取命中了!

壓力測試看效果

關閉開啟apc分別壓力測試對比一下你會發現開啟apc之後吞吐率會比沒開啟apc要提高許多。

# ab -n1000 -c10 http://www.111cn.net /test.php

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.