This article will introduce to you the solution to the crash of apache caused by using preg_match_all in win2003. Friends who have encountered such problems can refer to it for reference.
Apache/2.2.9 (Win32) + PHP/5.2.17, using the regular expression preg_match_all (such as preg_match_all("/ni(.*?)wo/", $html, $matches);) for analysis When matching the relatively long string $html (larger than 100,000 bytes, generally used to analyze the collected web page source code), the Apache server will crash and automatically restart.
There is this prompt in the Apache error log:
[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.
After consulting Apache official and forum information, I found that when using the regular preg_match_all or preg_match to analyze relatively long strings under the win platform, the cause of apache crash and restart is that the thread stack space ThreadStackSize allocated by default under the windows platform is too small. . The default value of win32 is only 256KB, while the default value under Linux is 8M. This is why the same program works normally under the Linux platform but not under the Win platform.
According to the official description of PCRE library: the pcre.recursion_limit size corresponding to 256 KB of stack space should not exceed 524.
Here is a table of safe values of pcre.recursion_limit for a variety of executable stack sizes:
The following is a recommended safety value corresponding to Stacksize and pcre.recursion_limit. If this value is exceeded, stack overflow is very likely to occur. Apache crash:
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
If you have not adjusted the stack size, you must add:
ini_set("pcre.recursion_limit", "524"); // PHP default is 100,000.
?>
To view specific errors, you can use the following code:
Description of the regular modifier isU:
i: means in-casesensitive, that is, case-insensitive
s: PCRE_DOTALL, indicating that the dot can match newline characters.
U: means PCRE_UNGREEDY, which means non-greedy, equivalent to .*? in perl/python language. During the matching process, for the .* regular expression, it will be executed immediately as soon as there is a match, instead of waiting for .* to search all the characters and then return them one by one. 🎜>
When using regular expressions, we should try to avoid recursive calls, which can easily lead to stack overflow. For example:
/
The code is as follows | Copy code
|
||||
|
ThreadsPerChild 200
http://www.bkjia.com/PHPjc/632107.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632107.htmlTechArticleThis article will introduce to you the solution to the apache crash caused by using preg_match_all in win2003. Friends who have encountered such problems References can be entered. Apache/2.2.9 (Win32) + PHP/5.2.17, in...