Net_Server
| From: | Richard Thomas | Date: | Fri, 30 Jul 2004 01:47:13 +0000 |
| Subject: | Net_Server | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-32349@lists.php.net to get a copy of this message | ||
Been using pear for a while now but new to how development works for
bear with me..
Been working on a project that requires a socket server, ended up
building my own and would like to donate some things I found after
comparing the 2. Examples provided are from my own code and would have
to be adjusted some to match.
In Driver.php add the following var
// Define our possible api extenders they all start as not defined
var $api_check = array( "cyberss_start" => 0,
"cyberss_end" => 0,
"cyberss_connect" => 0,
"cyberss_disconnect" => 0,
"cyberss_overload" => 0,
"cyberss_receive" => 0);
Then in each of the drivers in the start function add the following
// Lets check to see what api's the module defined
// This avoids having to do function or method exist every loop
foreach($this->api_check as $key => $value) {
if(function_exists($key)) {
$this->api_check[$key] = 1;
}
}
Now instead of doing
if (method_exists($this->callbackObj, "onStart")) {
$this->callbackObj->onStart(); }
You can do
if($this->api_check['cyberss_end']) {
$this->api->cyberss_end();
}
This kills 5? functions calls per loop, in my testing my method is
around 65% faster.. Its very small overall, looping 100000 times its
only a .05 microseconds diff in speed but every bit counts and it
should use fewer cpu resources.