From: jdespatis at yahoo dot fr
Operating system: Linux Debian
PHP version: 5.2.5
PHP Bug Type: Regexps related
Bug description: preg_replace_callback is very ver slow on a 36k xml file
Description:
------------
I have a 36k xml file
I launch preg_replace_callback on it, but php runs crazy 99% CPU
Reproduce code:
---------------
test case try this code with the 1087985.xml i give in attachment:
the aim is to cut the string ended by \r or \n or \x0, and launch a
specific function (protocol_analyse) on each message
<?php
function protocol_analyse($m) {
echo "protocol_analyse:\n";
print_r($m);
}
$buff = file_get_contents("1087985.xml");
$start = microtime(true);
$buff = preg_replace_callback("/([^\r\n\\x00]*)[\r\n\\x00]+/m",
"protocol_analyse",
$buff);
$end = microtime(true);
printf("Duration : %.2f", $end - $start);
?>
Expected result:
----------------
I expect the function to returns quick, but 99% CPU taken
Actual result:
--------------
Duration : 133.00 sec which is very very slow
--
Edit bug report at http://bugs.php.net/?id=43920&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=43920&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=43920&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=43920&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=43920&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=43920&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=43920&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=43920&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=43920&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=43920&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=43920&r=support
Expected behavior: http://bugs.php.net/fix.php?id=43920&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=43920&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=43920&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=43920&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=43920&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=43920&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=43920&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=43920&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=43920&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=43920&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=43920&r=mysqlcfg