国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > OS > Win2003 > 正文

win2003下PHP使用preg

2024-09-10 16:49:31
字體:
供稿:網(wǎng)友
這篇文章主要介紹了win2003下PHP使用preg_match_all導(dǎo)致apache崩潰問題的解決方法,詳細的分析了問題產(chǎn)生原因以及解決方案,需要的朋友可以參考下

小編的平臺是windows server 2003(32位系統(tǒng)) + Apache/2.2.9 (Win32) + PHP/5.2.17,在使用正則表達式 preg_match_all (如 preg_match_all("/ni(.*?)wo/", $html, $matches);)進行分析匹配比較長的字符串 $html 時(大于10萬字節(jié),一般用于分析采集回來的網(wǎng)頁源碼),Apache服務(wù)器會崩潰自動重啟。
    在Apache錯誤日志里有這樣的提示:
復(fù)制代碼 代碼如下:[Thu Apr 11 18:31:31 2013] [notice] Parent: child process exited with status 128 -- Restarting.
[Thu Apr 11 18:31:31 2013] [notice] Apache/2.2.9 (Win32) PHP/5.2.17 configured -- resuming normal operations
[Thu Apr 11 18:31:31 2013] [notice] Server built: Jun 13 2008 04:04:59
[Thu Apr 11 18:31:31 2013] [notice] Parent: Created child process 2964
[Thu Apr 11 18:31:31 2013] [notice] Disabled use of AcceptEx() WinSock2 API
[Thu Apr 11 18:31:31 2013] [notice] Child 2964: Child process is running
[Thu Apr 11 18:31:31 2013] [notice] Child 2964: Acquired the start mutex.
[Thu Apr 11 18:31:31 2013] [notice] Child 2964: Starting 350 worker threads.
[Thu Apr 11 18:31:31 2013] [notice] Child 2964: Listening on port 80.
    經(jīng)過查閱Apache官方以及論壇資料后,發(fā)現(xiàn)win平臺下用正則 preg_match_all 或preg_match 分析比較長的字符串時,導(dǎo)致apache崩潰重啟的原因是windows平臺下默認分配的線程堆??臻g ThreadStackSize 太小導(dǎo)致的。 win32默認只有256KB,而在 linux下默認值是 8M,這就是為什么同樣的程序在 linux平臺下正常,而在 win平臺下不正常的原因。
    根據(jù)PCRE library的官方說明:256 KB 的堆??臻g對應(yīng)的pcre.recursion_limit大小應(yīng)該不超過524。
Here is a table of safe values of pcre.recursion_limit for a variety of executable stack sizes:
下面就是一張Stacksize和pcre.recursion_limit對應(yīng)的建議安全值,超過這個數(shù)值就極有可能發(fā)生堆棧溢出,apache crash:
復(fù)制代碼 代碼如下:Stacksize   pcre.recursion_limit
 64 MB      134217
 32 MB      67108
 16 MB      33554
  8 MB      16777
  4 MB      8388
  2 MB      4194
  1 MB      2097
512 KB      1048
256 KB      524

如果你沒有調(diào)整堆棧大小,就必須在使用正則的PHP頁面最開頭加入:
復(fù)制代碼 代碼如下:<?php
ini_set("pcre.recursion_limit", "524"); // PHP default is 100,000.
?>

查看具體的錯誤可以使用下面的代碼:
復(fù)制代碼 代碼如下:$resultsArray = preg_match_all("/table.*?<a>/isU", $html, $contents);
if ($resultsArray === 0){
echo get_pcre_err();
}
function get_pcre_err(){
        $pcre_err = preg_last_error();  // PHP 5.2 and above.

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 乌拉特后旗| 岳西县| 大兴区| 宣恩县| 玛纳斯县| 嘉禾县| 武定县| 东城区| 顺义区| 南川市| 越西县| 遂昌县| 万全县| 渭南市| 孟津县| 桐庐县| 平顺县| 时尚| 武冈市| 格尔木市| 永春县| 保靖县| 柳州市| 保亭| 铅山县| 巴楚县| 义乌市| 社旗县| 什邡市| 郸城县| 自贡市| 汕尾市| 肇东市| 余姚市| 库伦旗| 苗栗市| 余姚市| 岑巩县| 依兰县| 江口县| 唐海县|