#23327 [Opn->Ver]: Crash / Strange beahaviour when using file() and preg_match()
| From: | sniper@php.net | Date: | Thu, 24 Apr 2003 18:41:58 +0000 |
| Subject: | #23327 [Opn->Ver]: Crash / Strange beahaviour when using file() and preg_match() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-38331@lists.php.net to get a copy of this message | ||
ID: 23327
Updated by: sniper@php.net
Reported By: sysadmin at alexdupre dot com
-Status: Open
+Status: Verified
-Bug Type: Unknown/Other Function
+Bug Type: Scripting Engine problem
Operating System: FreeBSD 4-STABLE
-PHP Version: 4CVS-2003-04-24 (stable)
+PHP Version: 4.3.2-RC
New Comment:
Here's a bit better example which show exactly what happens:
<?php
if ($stats2 = file('http://194.183.89.2/uptime.php')) {
preg_match("/averages?:
([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/",$stats2[0],$regs2);
var_dump($regs2);
}
if ($stats3 = file('http://194.183.89.3/uptime.php')) {
preg_match("/averages?:
([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/",$stats3[0],$regs3);
var_dump($regs3);
}
if ($stats4 = file('http://194.183.89.4/uptime.php')) {
preg_match("/averages?:
([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/",$stats4[0],$regs4);
var_dump($regs4);
}
var_dump($regs2);
var_dump($regs3);
var_dump($regs4);
?>
And output:
-----------
array(4) {
[0]=>
string(26) "averages: 2.80, 2.68, 2.46"
[1]=>
string(4) "2.80"
[2]=>
string(4) "2.68"
[3]=>
string(4) "2.46"
}
array(4) {
[0]=>
string(26) "averages: 0.62, 0.52, 0.46"
[1]=>
string(4) "0.62"
[2]=>
string(4) "0.52"
[3]=>
string(4) "0.46"
}
array(4) {
[0]=>
string(26) "averages: 1.10, 0.76, 0.74"
[1]=>
string(4) "1.10"
[2]=>
string(4) "0.76"
[3]=>
string(4) "0.74"
}
UNKNOWN:0
UNKNOWN:0
array(4) {
[0]=>
string(26) "averages: 1.10, 0.76, 0.74"
[1]=>
string(4) "1.10"
[2]=>
string(4) "0.76"
[3]=>
string(4) "0.74"
}
---
The last preg_match() call somehow mangles the $reg2 and $reg3
arrays??! (If I add more of these, always only the last $reg* array is
okay)
This doesn't seem quite right. (No idea where the problem is, file() or
preg_match())
Previous Comments:
------------------------------------------------------------------------
[2003-04-24 08:35:18] sysadmin at alexdupre dot com
Working script (using fopen/fgets/fclose):
<?php
if ($stats2 = fopen('http://194.183.89.2/uptime.php',
'r')) {
preg_match("/averages?:
([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/",fgets($stats2),$regs2);
fclose($stats2);
}
if ($stats3 = fopen('http://194.183.89.3/uptime.php',
'r')) {
preg_match("/averages?:
([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/",fgets($stats3),$regs3);
fclose($stats3);
}
if ($stats4 = fopen('http://194.183.89.4/uptime.php',
'r')) {
preg_match("/averages?:
([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/",fgets($stats4),$regs4);
fclose($stats4);
}
echo "www2: $regs2[1], $regs2[2], $regs2[3]\n" .
"www3: $regs3[1], $regs3[2], $regs3[3]\n" .
"www4: $regs4[1], $regs4[2], $regs4[3]\n";
?>
$ php work.php
www2: 2.29, 2.73, 2.94
www3: 0.86, 0.77, 0.82
www4: 0.66, 0.72, 0.70
Not working script (using file):
<?php
if ($stats2 = file('http://194.183.89.2/uptime.php')) {
preg_match("/averages?:
([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/",$stats2[0],$regs2);
}
if ($stats3 = file('http://194.183.89.3/uptime.php')) {
preg_match("/averages?:
([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/",$stats3[0],$regs3);
}
if ($stats4 = file('http://194.183.89.4/uptime.php')) {
preg_match("/averages?:
([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/",$stats4[0],$regs4);
}
echo "www2: $regs2[1], $regs2[2], $regs2[3]\n" .
"www3: $regs3[1], $regs3[2], $regs3[3]\n" .
"www4: $regs4[1], $regs4[2], $regs4[3]\n";
?>
$ php fail.php
www2: , ,
www3: T, T, P
www4: 0.38, 0.62, 0.66
php in free(): warning: chunk is already free
php in free(): warning: chunk is already free
php in free(): warning: chunk is already free
php in free(): warning: chunk is already free
php in free(): warning: chunk is already free
php in free(): warning: chunk is already free
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=23327&edit=1