|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-04-24 08:35 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Tue Feb 03 18:00:02 2026 UTC |
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())