コード例 #1
0
ファイル: asyncsocket.php プロジェクト: bitemyapp/Sblam
 function onPing($callback, $nexttime)
 {
     $this->onPing = $callback;
     AsyncSocket::nextPing($nexttime);
 }
コード例 #2
0
ファイル: asyncdns.php プロジェクト: bitemyapp/Sblam
 /** query nameserver
 		@return instance of AsyncDNS that will return acutual result
 	*/
 static function query($host, $type = 'A', $class = 'IN')
 {
     static $queries;
     if (preg_match('/^(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)$/', $host, $regs)) {
         $host = $regs[4] . '.' . $regs[3] . '.' . $regs[2] . '.' . $regs[1] . '.in-addr.arpa.';
         $type = 'PTR';
     }
     $key = $class . $type . $host;
     if (!isset(self::$resolvers[$key])) {
         self::$resolvers[$key] = new AsyncDNS($host, $type, $class, $key);
         $queries++;
         if ($queries % 10 == 0) {
             AsyncSocket::poll();
         }
         // prevents queue from getting too large
     }
     return self::$resolvers[$key];
 }
コード例 #3
0
ファイル: sblam.php プロジェクト: bitemyapp/Sblam
 function testPost(ISblamPost $p)
 {
     if (!$this->testPhases) {
         return array(0, 0, "No tests");
     }
     $profiling = array();
     $asyncpolltime = 0;
     $results = array();
     $totalspam = 0;
     ksort($this->testPhases, SORT_NUMERIC);
     foreach ($this->testPhases as $phase => $phaseTests) {
         foreach ($phaseTests as $test) {
             if (!$test instanceof ISblamTestPost) {
                 continue;
             }
             $start = microtime(true);
             $test->preTestPost($p);
             $profiling["p{$phase}:" . get_class($test)] = microtime(true) - $start;
         }
         foreach ($phaseTests as $test) {
             if (!$test instanceof ISblamTestPost) {
                 continue;
             }
             $start = microtime(true);
             AsyncSocket::poll(0);
             // get those queued DNS queries
             $asyncpolltime += microtime(true) - $start;
             $start = microtime(true);
             $tmpres = $test->testPost($p);
             $profiling["t{$phase}:" . get_class($test)] = microtime(true) - $start;
             $results[] = $tmpres;
             if ($tmpres && is_numeric($tmpres[0])) {
                 $totalspam += $tmpres[0];
             }
             if ($totalspam > self::EARLY_ESCAPE_LIMIT) {
                 $results[] = array(6, 1, "Early escape", $profiling);
                 break 2;
             }
         }
     }
     $profiling['tst:AsyncSocket'] = $asyncpolltime;
     $results = $this->sumResults($results);
     $results[2] = implode('; ', $results[2]);
     $results[3] = $profiling;
     return $results;
 }