#24826 [Com]: PEAR::Net Ping Bug
| From: | Progman2002 at gmx dot de | Date: | Wed, 13 Aug 2003 11:31:33 +0000 |
| Subject: | #24826 [Com]: PEAR::Net Ping Bug | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-19672@lists.php.net to get a copy of this message | ||
ID: 24826
Comment by: Progman2002 at gmx dot de
Reported By: young at sl dot com dot ua
Status: Closed
Bug Type: PEAR related
Operating System: Linux
PHP Version: 4.3.2
Assigned To: jan
New Comment:
There is still a bug:
[var_dump()-snip]
string(62) "2 packets transmitted, 2 received, 0% packet loss, time
1007ms"
[6]=>
string(55) "rtt min/avg/max/mdev = 224.307/224.317/224.327/0.010
ms"
}
["_sysname"]=>
string(5) "linux"
["_round_trip"]=>
array(3) {
["min"]=>
string(7) "224.317"
["avg"]=>
string(7) "224.327"
["max"]=>
string(5) "0.010"
}
[/snip]
You can see he read out the wrong values for the round-trip-infos.
There are 2 solutions. The first one is to decrease all indices by one
or the second solution is this patch
Index: Ping.php
===================================================================
RCS file: /repository/pear/Net_Ping/Ping.php,v
retrieving revision 1.26
diff -u -r1.26 Ping.php
--- Ping.php 30 Jul 2003 20:33:55 -0000 1.26
+++ Ping.php 13 Aug 2003 11:13:41 -0000
@@ -602,18 +602,11 @@
$loss = explode(' ', $stats[2]);
$this->_loss = (int)$loss[1];
- $round_trip = explode('/', str_replace('=', '/',
substr($this->_raw_data[$raw_data_len - 1], 0, -3)));
-
- /* if mdev field exists, shift input one unit left */
- if (strpos($this->_raw_data[$raw_data_len - 1], 'mdev'))
{
- /* do not forget the rtt field */
- $this->_round_trip['min'] = ltrim($round_trip[5]);
- $this->_round_trip['avg'] = $round_trip[6];
- $this->_round_trip['max'] = $round_trip[7];
- } else {
- $this->_round_trip['min'] = ltrim($round_trip[4]);
- $this->_round_trip['avg'] = $round_trip[5];
- $this->_round_trip['max'] = $round_trip[6];
+ $round_trip_infos = explode(' ',
$this->_raw_data[$raw_data_len - 1]);
+ $round_trip['names'] = explode('/',
$round_trip_infos[1]);
+ $round_trip['values'] = explode('/',
$round_trip_infos[3]);
+ for($i=0; $i < min(count($round_trip['names']),
count($round_trip['values'])); $i++) {
+ $this->_round_trip[$round_trip['names'][$i]] =
$round_trip['values'][$i];
}
}
The patch will also add a "mdev" index, if the ping-command produce it
Previous Comments:
------------------------------------------------------------------------
[2003-07-30 15:33:45] nicos@php.net
This bug has been fixed in CVS.
In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
Thank you for the report, and for helping us make PHP better.
.
------------------------------------------------------------------------
[2003-07-27 10:44:47] mj@php.net
The patch looks fine for me and it obviously does not break anything.
Can any of guys take care of committing it and rolling a new release
afterwards?
------------------------------------------------------------------------
[2003-07-27 09:30:09] nicos@php.net
Lack of linux! What! Jan!
:-)
I can commit too. It should work fine with every OS, but I'm not sure
thats why I wait for feedback of the maintainer...
------------------------------------------------------------------------
[2003-07-27 07:53:19] jan@php.net
Hi,
I can commit the patch, but I can't test it due to a
lack of linux around here. Can you please make sure it
works AND doesn't brake anything else?
Jan
------------------------------------------------------------------------
[2003-07-27 04:29:48] nicos@php.net
Here is the patch...
Is it ok?
cvs server: Diffing .
Index: Ping.php
===================================================================
RCS file: /repository/pear/Net_Ping/Ping.php,v
retrieving revision 1.25
diff -u -u -r1.25 Ping.php
--- Ping.php 14 Jul 2003 20:26:55 -0000 1.25
+++ Ping.php 27 Jul 2003 09:28:27 -0000
@@ -606,13 +606,14 @@
/* if mdev field exists, shift input one unit left */
if (strpos($this->_raw_data[$raw_data_len - 1], 'mdev'))
{
+ /* do not forget the rtt field */
+ $this->_round_trip['min'] = ltrim($round_trip[5]);
+ $this->_round_trip['avg'] = $round_trip[6];
+ $this->_round_trip['max'] = $round_trip[7];
+ } else {
$this->_round_trip['min'] = ltrim($round_trip[4]);
$this->_round_trip['avg'] = $round_trip[5];
$this->_round_trip['max'] = $round_trip[6];
- } else {
- $this->_round_trip['min'] = ltrim($round_trip[3]);
- $this->_round_trip['avg'] = $round_trip[4];
- $this->_round_trip['max'] = $round_trip[5];
}
}
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/24826
--
Edit this bug report at http://bugs.php.net/?id=24826&edit=1