久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長(zhǎng)資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      利用 OPcache 擴(kuò)展提升 PHP7 性能技巧

      利用 OPcache 擴(kuò)展提升 PHP7 性能技巧

      推薦(免費(fèi)):PHP7

      No matter where I am, I will reply you immediately when I see the email.My Email: echo "YUBzYW1lZ28uY29tCg==" | base64 -d
      前言
      十一點(diǎn)半了,沉淀時(shí)間到了。

      PHP在運(yùn)行的時(shí)候,存在這樣的一個(gè)流程,先將PHP代碼預(yù)編譯,生成字節(jié)碼后再加載到內(nèi)存里,最后CPU在內(nèi)存上執(zhí)行編譯后的字節(jié)碼片段。我們會(huì)發(fā)現(xiàn),在執(zhí)行PHP程序的時(shí)候,每次都經(jīng)過(guò)這樣的流程,此非浪費(fèi)Time,是的,很容易聯(lián)想到:為何不向C++語(yǔ)言看齊呢,將源碼編譯成可直接加載到內(nèi)存so哥呢?呃呃?。快拿出你的步槍,裝上這顆子彈OPcache。自從PHP5.5.0出來(lái)后,就內(nèi)置此zend擴(kuò)展了。


      What is OPcache
      OPcache是PHP中的Zend擴(kuò)展,可以大大提升PHP的性能。
      OPcache 通過(guò)將 PHP 腳本預(yù)編譯的字節(jié)碼存儲(chǔ)到共享內(nèi)存中來(lái)提升 PHP 的性能, 存儲(chǔ)預(yù)編譯字節(jié)碼的好處就是 省去了每次加載和解析 PHP 腳本的開(kāi)銷。


      Judge whether it has been extended OPcache

      ?  ~ php -m | grep OPcache Zend OPcache Zend OPcache

      倘若沒(méi)有開(kāi)啟的話,可以在php.ini配置中開(kāi)啟
      /home/samego/service/php7.2/php.ini

      ?  ~ echo zend_extension="opcache.so" >> /home/samego/service/php7.2/php.ini

      About OPcache configure
      接下來(lái),我們需要在 PHP 的配置文件中啟用 OPcache(默認(rèn)是關(guān)閉的):

      opcache.enable=1

      下面我們繼續(xù)對(duì) OPcache 進(jìn)行一些優(yōu)化配置:

      opcache.memory_consumption=512

      這個(gè)配置表示你想要分配給 OPcache 的內(nèi)存空間(單位:MB),設(shè)置一個(gè)大于 64 的值即可。

      opcache.interned_strings_buffer=64

      這個(gè)配置表示你想要分配給實(shí)際字符串的空間(單位:MB),設(shè)置一個(gè)大于 16 的值即可。

      opcache.max_accelerated_files=32531

      這個(gè)配置表示可以緩存多少個(gè)腳本,將這個(gè)值盡可能設(shè)置為與項(xiàng)目包含的腳本數(shù)接近(或更大)。

      opcache.validate_timestamps=0

      改配置值用于重新驗(yàn)證腳本,如果設(shè)置為 0(性能最佳),需要手動(dòng)在每次 PHP 代碼更改后手動(dòng)清除 OPcache。如果你不想要手動(dòng)清除,可以將其設(shè)置為 1 并通過(guò) opcache.revalidate_freq 配置重新驗(yàn)證間隔,這可能會(huì)消耗一些性能,因?yàn)樾枰扛?x 秒檢查更改。

      opcache.save_comments=1

      這個(gè)配置會(huì)在腳本中保留注釋,我推薦開(kāi)啟該選項(xiàng),因?yàn)橐恍?kù)依賴于這個(gè)配置,并且我也找不出什么關(guān)閉它的好處。

      opcache.fast_shutdown=0

      快速關(guān)閉會(huì)給一個(gè)更快速清理內(nèi)存的機(jī)制,不過(guò),在我的基準(zhǔn)測(cè)試中,更慢一些,可能這會(huì)應(yīng)用帶來(lái)一些性能提升,但是你需要自己去嘗試。

      所以,最終的配置優(yōu)化長(zhǎng)這樣:

      opcache.enable=1 opcache.memory_consumption=512 opcache.interned_strings_buffer=64 opcache.max_accelerated_files=32531 opcache.validate_timestamps=0 opcache.save_comments=1 opcache.fast_shutdown=0

      你可以使用這些配置值進(jìn)行實(shí)驗(yàn),具體配置值取決于你的應(yīng)用大小和服務(wù)器配置。
      學(xué)習(xí)于Laravel社區(qū)


      Laravel OPcache

      • install

        ?  ~ composer require appstract/laravel-opcache
      • configure

        ?  ~ php artisan vendor:publish --provider="AppstractOpcacheOpcacheServiceProvider" --tag="config"
      • command

      # Clear OPcache: ?  ~ php artisan opcache:clear  # Show OPcache config: ?  ~ php artisan opcache:config  # Show OPcache status: ?  ~ php artisan opcache:status  # Pre-compile your application code: ?  ~ php artisan opcache:optimize

      拭目以待的場(chǎng)景測(cè)試

      個(gè)人比較喜歡數(shù)據(jù)說(shuō)話
      場(chǎng)景:(1)請(qǐng)求GET接口 (2)測(cè)試次數(shù)10 (3)并發(fā)數(shù)為100

      case non-extension

      1000個(gè)請(qǐng)求,花費(fèi)32.32秒,每秒30.94個(gè)請(qǐng)求

      Transactions:               1000 hits Availability:             100.00 % Elapsed time:              32.32 secs Data transferred:           0.97 MB Response time:              0.32 secs Transaction rate:          30.94 trans/sec Throughput:             0.03 MB/sec Concurrency:                9.96 Successful transactions:        1000 Failed transactions:               0 Longest transaction:            0.44 Shortest transaction:           0.11

      case had extend

      1000個(gè)請(qǐng)求,花費(fèi)2.94秒,每秒340.14個(gè)請(qǐng)求

      Transactions:               1000 hits Availability:             100.00 % Elapsed time:               2.94 secs Data transferred:           0.97 MB Response time:              0.03 secs Transaction rate:         340.14 trans/sec Throughput:             0.33 MB/sec Concurrency:                9.86 Successful transactions:        1000 Failed transactions:               0 Longest transaction:            0.29 Shortest transaction:           0.01

      看到這組數(shù)據(jù),我甚是高興,無(wú)比的喜悅。在性能方面,形成如此鮮明的對(duì)比,我二話不說(shuō)~OPcache is right

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)