cvs: pear /Net_IRC IRC.php

From: Date: Sun, 28 Apr 2002 17:43:08 +0000
Subject: cvs: pear /Net_IRC IRC.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-3606@lists.php.net to get a copy of this message
cox Sun Apr 28 13:43:08 2002 EDT Modified files: /pear/Net_IRC IRC.php Log: Optimized the stats collector Introduced tx_idle to stats Index: pear/Net_IRC/IRC.php diff -u pear/Net_IRC/IRC.php:1.4 pear/Net_IRC/IRC.php:1.5 --- pear/Net_IRC/IRC.php:1.4 Sun Apr 28 10:42:22 2002 +++ pear/Net_IRC/IRC.php Sun Apr 28 13:43:06 2002 @@ -17,7 +17,7 @@ // | | // +----------------------------------------------------------------------+ // -// $Id: IRC.php,v 1.4 2002/04/28 14:42:22 cox Exp $ +// $Id: IRC.php,v 1.5 2002/04/28 17:43:06 cox Exp $ /** * Class for handling the client side of the IRC protocol (RFC 1459) @@ -88,13 +88,13 @@ } $this->log(3, "connected"); $this->socket = $sd; + $this->initStats(); $this->command('USER '. $options['identd'] . ' '. $options['host'] . ' '. $options['server'] . ' '. ':' . $options['realname']); $this->command('NICK ' . $options['nick']); - $this->initStats(); while($this->readEvent(true) == 'MOTD'); socket_set_blocking($sd, false); @@ -179,6 +179,7 @@ return false; } else { $this->log(4, "<- $command"); + $this->updateStats('tx'); } return true; } @@ -199,8 +200,6 @@ do { $receive = rtrim(fgets($this->socket, 1024)); if (!$receive) { - // XXX Only update stats for example each 2 seconds - $this->updateStats(false); if (!$block) { return null; } else { @@ -208,7 +207,7 @@ continue; } } else { - $this->updateStats(true); + $this->updateStats('rx'); $this->log(4, "-> $receive"); } } while (!$receive); @@ -338,19 +337,13 @@ /** * Updates the internal stats * + * @param string type 'rx' or 'tx' * @access private */ // XXX rename to _updateStats() - // XXX Introduce stats levels (none, normal, full) - function updateStats($data) + function updateStats($type = 'rx') { - if ($data) { - $this->stats['rx_idle'] = 0; - } else { - $this->stats['rx_idle'] += time() - $this->stats['last_updated']; - $this->log(6, "Updating idle time to: " . $this->stats['rx_idle']); - } - $this->stats['last_updated'] = time(); + $this->stats[$type . '_idle_since'] = time(); } /** @@ -360,6 +353,7 @@ */ // XXX This should be enhanced to be able to track the different // kinds of flood attacks (maybe in a different class) + // XXX Introduce stats levels (none, normal, full) function updateEventStats($event, $args = array()) { $this->log(5, "Updating event $event"); @@ -402,17 +396,21 @@ // XXX Rename to _initStats() function initStats() { + $this->stats['started'] = time(); $this->stats['rx_idle'] = 0; - $this->stats['last_updated'] = time(); + $this->stats['rx_idle_since'] = time(); + $this->stats['tx_idle'] = 0; + $this->stats['tx_idle_since'] = time(); $this->stats['events'] = array(); - $this->stats['started'] = time(); } /** * Get the internal stats of the connection. Params accepted for $label: * - rx_idle: The seconds passed since the last time we received a * message from the server - * - last_updated: The last date (timestamp) when the stats where updated + * - rx_idle_since: The last date (timestamp) we received a message from the server + * - tx_idle The seconds since the last time we sent a message + * - tx_idle_since: The last time we sent a message to the server * - started: The date (timestamp) when the socket was openned * - running: The amount of seconds since the start time * @@ -422,6 +420,8 @@ */ function getStats($label = null) { + $this->stats['rx_idle'] = time() - $this->stats['rx_idle_since']; + $this->stats['tx_idle'] = time() - $this->stats['tx_idle_since']; $this->stats['running'] = time() - $this->stats['started']; if ($label) { return isset($this->stats[$label]) ? $this->stats[$label] : false; @@ -442,7 +442,7 @@ } /** - * Gets a option of this instance + * Gets an option of this instance * * @param string $options The option to retrieve * @return string The value of the option

« previous php.pear.cvs (#3606) next »