PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Networking » Net_Server » Bug #6098

Net_Server onIdle hook

Details

Request #6098Net_Server onIdle hook
Submitted2005-11-28 20:15 UTC
Fromerudd at netfor dot com
Assignedcweiske
StatusClosed
PackageNet_Server
PHP VersionIrrelevant
Roadmaps(Not assigned)

Comments

[2005-11-28 20:15 UTC] erudd at netfor dot com

Description:
------------
This patch adds an onIdle member to the handler class. where if the member function is defined it is called approximately every 30 seconds. (eventually it should be customizable by the derived class, or via "set" functions)

Reason:
so the daemon can perform tasks w/o needing to be "poked" with network traffic. I use this to provide a simple web interface to a daemon that runs tasks every 5 to 10 minutes, so the web interface to the running daemon is a secondary function, not the primary.

Test script:
---------------
--- Sequential.php 2005-11-25 15:09:16.000000000 -0500
+++ Sequential.php 2005-11-28 14:56:40.000000000 -0500
@@ -111,6 +111,17 @@
$this->callbackObj->onStart();
}

+ if (method_exists($this->callbackObj, "onIdle")) {
+ $this->idling = true;
+ $this->_idlelast = time();
+ $this->_idletimeout = 30;
+ $this->_idlecheck = 10;
+ } else {
+ $this->idling = false;
+ $this->_idletimeout = NULL;
+ $this->_idlecheck = NULL;
+ }
+
while (true)
{
$readFDs = array();
@ -121,15 +132,20 @@
if (isset($this->clientFD[$i]))
array_push($readFDs, $this->clientFD[$i]);
}
-
// block and wait for data or new connection
- $ready = @socket_select($readFDs, $this->null, $this->null, NULL);
+ $ready = @socket_select($readFDs, $this->null, $this->null, $this->_idlecheck);

if ($ready === false) {
$this->_sendDebugMessage("socket_select failed.");
$this->shutdown();
}

+ //Idling and no data
+ if ($ready == 0 && ($this->_idlelast + $this->_idletimeout) < time()) {
+ $this->_idlelast = time();
+ $this->callbackObj->onIdle();
+ continue;
+ }
// check for new connection
if (in_array($this->initFD, $readFDs)) {
$newClient = $this->acceptConnection($this->initFD);

[2006-03-09 00:06 UTC] erudd at netfor dot com

fixed summary