Windows 2008 下 PHP 開(kāi)啟 opcache 后頻繁 500 錯(cuò)誤解決方式

最近公司后臺(tái)訪問(wèn)速度下降惰许,操作卡頓席覆,公司后臺(tái)環(huán)境是 windows server 2008 + iis7 + php5.6,于是在參考網(wǎng)上解決方案后汹买,覺(jué)得使用 opcache 最為方便佩伤,于是參考幾篇配置示例文檔后,在線部署了晦毙。經(jīng)過(guò)一段時(shí)間體驗(yàn)后生巡,發(fā)現(xiàn)確實(shí)快了很多,但是相應(yīng)的出現(xiàn)了一個(gè)以前幾乎沒(méi)見(jiàn)過(guò)的問(wèn)題见妒,訪問(wèn)后臺(tái)時(shí)經(jīng)常性 500 錯(cuò)誤孤荣,但是刷新頁(yè)面就恢復(fù)正常了,將這個(gè)現(xiàn)象在網(wǎng)上搜了一番须揣,確實(shí)存在這個(gè)問(wèn)題盐股,但是找了許多帖子也沒(méi)有發(fā)現(xiàn)靠譜的解決方案,于是就擱置了這個(gè)問(wèn)題耻卡,刷新頁(yè)面重試也是可以忍受的疯汁。

后來(lái),經(jīng)公司運(yùn)營(yíng)反饋發(fā)現(xiàn)卵酪,500 錯(cuò)誤發(fā)生的太頻繁了幌蚊,另外有時(shí)候刷新也不管用秸谢,因?yàn)楹笈_(tái)有些頁(yè)面會(huì)一次性批量請(qǐng)求后端接口,然后幾乎都是 500霹肝,這個(gè)問(wèn)題就有些嚴(yán)重了估蹄,于是重新開(kāi)始在網(wǎng)上尋求解決方式。

搜索到兩個(gè)方案如下:

1. 修改 IIS 應(yīng)用池配置

在 Internet 信息服務(wù)(IIS)管理器下的應(yīng)用程序池中選擇應(yīng)用沫换,右鍵-高級(jí)設(shè)置-標(biāo)識(shí)臭蚁,將 ApplicationPoolIdentity 修改為 LocalSystem,經(jīng)驗(yàn)證讯赏,失敗垮兑。


2. 修改 opcache 配置

在 PHP 手冊(cè)中有這么一個(gè)配置項(xiàng)

opcache.mmap_base string
在 Windows 平臺(tái)上共享內(nèi)存段的基地址。 所有的 PHP 進(jìn)程都將共享內(nèi)存映射到同樣的地址空間漱挎。 使用此配置指令避免“無(wú)法重新附加到基地址”的錯(cuò)誤系枪。

另外,在評(píng)論中有下面這段話磕谅,

When using PHP on a windows platform and enabling opcache, you might run into occasional 500 errors. These will appear to show up entirely random.
When this happens, your windows Event log (Windows Logs/Application) will show (probably multiple) entries from Zend OPcache with Event ID 487. Further information will state the following error message: "Base address marks unusable memory region".
This issue can be resolved by adding the following to your php.ini:
opcache.mmap_base = 0x20000000
Unfortunately I do not know the significance of the value "0x20000000". I can only tell you that this value works to solve the problem (Tried and tested)

大致意思是當(dāng)我們?cè)?windows 平臺(tái)下開(kāi)啟 opcache 時(shí)私爷,你可能發(fā)現(xiàn)運(yùn)行時(shí)出現(xiàn)隨機(jī) 500 錯(cuò)誤,然后在 php.ini 中添加一行配置 opcache.mmap_base = 0x20000000 可以解決膊夹。不幸的是衬浑,我不知道值“0x20000000”的意義,我只能告訴你這個(gè)值可以解決這個(gè)問(wèn)題放刨。
經(jīng)過(guò)驗(yàn)證工秩,成功解決 500 錯(cuò)誤!

下面貼下我自己的 opcache 配置

[opcache]
zend_extension="C:/php5.6/ext/php_opcache.dll"
; Determines if Zend OPCache is enabled
opcache.enable=1

; Determines if Zend OPCache is enabled for the CLI version of PHP
opcache.enable_cli=1

opcache.mmap_base=0x20000000

; The OPcache shared memory storage size.
opcache.memory_consumption=128

; The amount of memory for interned strings in Mbytes.
opcache.interned_strings_buffer=8

; The maximum number of keys (scripts) in the OPcache hash table.
; Only numbers between 200 and 100000 are allowed.
opcache.max_accelerated_files=20000

; The maximum percentage of "wasted" memory until a restart is scheduled.
opcache.max_wasted_percentage=10

; When this directive is enabled, the OPcache appends the current working
; directory to the script key, thus eliminating possible collisions between
; files with the same name (basename). Disabling the directive improves
; performance, but may break existing applications.
;opcache.use_cwd=1

; When disabled, you must reset the OPcache manually or restart the
; webserver for changes to the filesystem to take effect.
opcache.validate_timestamps=1

; How often (in seconds) to check file timestamps for changes to the shared
; memory storage allocation. ("1" means validate once per second, but only
; once per request. "0" means always validate)
opcache.revalidate_freq=60

; Enables or disables file search in include_path optimization
;opcache.revalidate_path=0

; If disabled, all PHPDoc comments are dropped from the code to reduce the
; size of the optimized code.
;opcache.save_comments=1

; If disabled, PHPDoc comments are not loaded from SHM, so "Doc Comments"
; may be always stored (save_comments=1), but not loaded by applications
; that don't need them anyway.
;opcache.load_comments=1

; If enabled, a fast shutdown sequence is used for the accelerated code
opcache.fast_shutdown=1

; Allow file existence override (file_exists, etc.) performance feature.
;opcache.enable_file_override=0

; A bitmask, where each bit enables or disables the appropriate OPcache
; passes
;opcache.optimization_level=0xffffffff

;opcache.inherited_hack=1
;opcache.dups_fix=0

; The location of the OPcache blacklist file (wildcards allowed).
; Each OPcache blacklist file is a text file that holds the names of files
; that should not be accelerated. The file format is to add each filename
; to a new line. The filename may be a full path or just a file prefix
; (i.e., /var/www/x  blacklists all the files and directories in /var/www
; that start with 'x'). Line starting with a ; are ignored (comments).
;opcache.blacklist_filename="D:/opcache_blacklist.txt"

; Allows exclusion of large files from being cached. By default all files
; are cached.
;opcache.max_file_size=0

; Check the cache checksum each N requests.
; The default value of "0" means that the checks are disabled.
;opcache.consistency_checks=0

; How long to wait (in seconds) for a scheduled restart to begin if the cache
; is not being accessed.
opcache.force_restart_timeout=120

; OPcache error_log file name. Empty string assumes "stderr".
;opcache.error_log="D:/log/opcache/err.log"

; All OPcache errors go to the Web server log.
; By default, only fatal errors (level 0) or errors (level 1) are logged.
; You can also enable warnings (level 2), info messages (level 3) or
; debug messages (level 4).
;opcache.log_verbosity_level=1

; Preferred Shared Memory back-end. Leave empty and let the system decide.
;opcache.preferred_memory_model=

; Protect the shared memory from unexpected writing during script execution.
; Useful for internal debugging only.
;opcache.protect_memory=0
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末进统,一起剝皮案震驚了整個(gè)濱河市助币,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌螟碎,老刑警劉巖眉菱,帶你破解...
    沈念sama閱讀 212,542評(píng)論 6 493
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異抚芦,居然都是意外死亡倍谜,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,596評(píng)論 3 385
  • 文/潘曉璐 我一進(jìn)店門叉抡,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)尔崔,“玉大人,你說(shuō)我怎么就攤上這事褥民〖敬海” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 158,021評(píng)論 0 348
  • 文/不壞的土叔 我叫張陵消返,是天一觀的道長(zhǎng)载弄。 經(jīng)常有香客問(wèn)我耘拇,道長(zhǎng),這世上最難降的妖魔是什么宇攻? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 56,682評(píng)論 1 284
  • 正文 為了忘掉前任惫叛,我火速辦了婚禮,結(jié)果婚禮上逞刷,老公的妹妹穿的比我還像新娘嘉涌。我一直安慰自己,他們只是感情好夸浅,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,792評(píng)論 6 386
  • 文/花漫 我一把揭開(kāi)白布仑最。 她就那樣靜靜地躺著,像睡著了一般帆喇。 火紅的嫁衣襯著肌膚如雪警医。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 49,985評(píng)論 1 291
  • 那天坯钦,我揣著相機(jī)與錄音预皇,去河邊找鬼。 笑死葫笼,一個(gè)胖子當(dāng)著我的面吹牛深啤,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播路星,決...
    沈念sama閱讀 39,107評(píng)論 3 410
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼诱桂!你這毒婦竟也來(lái)了洋丐?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 37,845評(píng)論 0 268
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤挥等,失蹤者是張志新(化名)和其女友劉穎友绝,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體肝劲,經(jīng)...
    沈念sama閱讀 44,299評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡迁客,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,612評(píng)論 2 327
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了辞槐。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片掷漱。...
    茶點(diǎn)故事閱讀 38,747評(píng)論 1 341
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖榄檬,靈堂內(nèi)的尸體忽然破棺而出卜范,到底是詐尸還是另有隱情,我是刑警寧澤鹿榜,帶...
    沈念sama閱讀 34,441評(píng)論 4 333
  • 正文 年R本政府宣布海雪,位于F島的核電站锦爵,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏奥裸。R本人自食惡果不足惜险掀,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 40,072評(píng)論 3 317
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望湾宙。 院中可真熱鬧樟氢,春花似錦、人聲如沸创倔。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,828評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)畦攘。三九已至霸妹,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間知押,已是汗流浹背叹螟。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,069評(píng)論 1 267
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留台盯,地道東北人罢绽。 一個(gè)月前我還...
    沈念sama閱讀 46,545評(píng)論 2 362
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像静盅,于是被迫代替她去往敵國(guó)和親良价。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,658評(píng)論 2 350