中文字幕日韩一区二区_国产一区二区av_国产毛片av_久久久久国产一区_色婷婷电影_国产一区二区精品

提高define性能的php擴(kuò)展hidef的安裝和使用

官網(wǎng):http://pecl.php.NET/package/hidef
簡介:
  Allow definition of user defined constants in simple ini files, which are then processed like internal constants, without any
of the usual performance penalties.
  允許使用簡單的ini文件來定義需要的常量,就像使用內(nèi)部變量一樣,而且沒有使用Define的性能問題。

作者說Hidef is initialized in php module init, before apache starts spawning children.
在apache啟動前,php啟動時創(chuàng)建并初始化了這些常量,這樣就不需要在php里define常量了,性能自然沒有任何問題了!
在Nginx下同樣可用,以下是安裝過程:

1、下載并解壓進(jìn)入目錄

# wget http://pecl.php.NET/get/hidef-0.1.8.tgz
# tar zxvf hidef-0.1.8.tgz
# cd hidef-0.1.8

2、沒有configure文件,執(zhí)行phpize創(chuàng)建該文件

# /usr/local/webserver/php/bin/phpize
# ./configure --enable-hidef --with-php-config=/usr/local/webserver/php/bin/php-config
# make
# make install

3、添加到php.ini文件里面

# vi /usr/local/webserver/php/etc/php.ini

-----------------------------------------------
extension=hidef.so
hidef.ini_path=/usr/local/webserver/php/etc/
------------------------------------------------------------------------------

注意,如果php.ini文件里面沒有定義hidef.ini_path,則默認(rèn).ini文件讀取位置為/hidef,只需手工創(chuàng)建文件 vi /hidef/hidef.ini即可。

# vi /usr/local/webserver/php/etc/hidef.ini(此處根據(jù)情況自己調(diào)整路徑)
復(fù)制代碼 代碼如下:
[hidef]
int ANSWER = 42;
str HX = "9enjoy";
float PIE = 3.14159;

這里整數(shù)用int,浮點(diǎn)數(shù)用float,字符串用str。
字符串str的值使用雙引號來包含,或者直接寫字符串內(nèi)容。如果使用單引號,將會把單引號也做為字符串的內(nèi)容。
如str HX='9enjoy',實(shí)際存儲的不是9enjoy,是'9enjoy'。

4、重新加載php-fpm即可

# /usr/local/webserver/php/sbin/php-fpm reload

此時,查看phpinfo()的結(jié)果,在hidef處就可以看到定義的變量。


-----------------------------------------------------------------------------

附:

如果使用了APC,apc提供了定義常量的方法。apc_define_constants和apc_load_constants。apc_define_constants將常量轉(zhuǎn)為數(shù)組存到一個user cache中。雖然把常量存在了內(nèi)存中,但每次php請求時,仍然需要讀cache,分別定義,因此也不會有什么明顯的性能提升。我測試了下定義25個常量,使用apc的函數(shù)比直接定義常量快了0.01ms。

這樣使用:
if(!apc_load_constants('defined')) {
    $constants = array(
        'HX'   => TRUE,
        'D_BUG' => 1
    );
    apc_define_constants('defined', $constants);
}

define() is notoriously slow. Since the main benefit of APC is to increase the performance of scripts/applications, this mechanism is provided to streamline the process of mass constant definition. However, this function does not perform as well as anticipated.

For a better-performing solution, try the hidef extension from PECL.

APC的文檔中推薦使用hidef。

php技術(shù)提高define性能的php擴(kuò)展hidef的安裝和使用,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 久久一热 | 亚洲国产成人精品久久久国产成人一区 | 免费一级淫片aaa片毛片a级 | 精品国产一区二区三区久久影院 | 久久精品小视频 | 亚洲国产精品一区二区三区 | 在线播放亚洲 | 国产a区 | 久久精品高清视频 | 久久精品国产99国产精品亚洲 | 亚洲欧美在线观看视频 | 欧美性受xxxx白人性爽 | 国产精品xxxx| 91视频在线看 | 亚洲精品久久久久久国产精华液 | 国产视频一区在线 | 中文一区二区 | 日本中出视频 | 日本又色又爽又黄又高潮 | 99综合网| 中文字幕不卡在线观看 | 人成精品| 超碰在线网站 | 色本道 | 99色在线 | 精品久久久久久久久久久 | 欧美一区二区在线观看 | 欧美日韩精品一区二区三区蜜桃 | 中文字幕一区二区三区精彩视频 | 99热碰| 一级欧美| 激情在线视频网站 | 中文在线一区二区 | 亚洲综合日韩精品欧美综合区 | 91麻豆精品国产91久久久更新资源速度超快 | 成人精品视频在线观看 | 狠狠涩| 91天堂网| 综合久 | 亚州精品天堂中文字幕 | 国产在线观看一区 |