/** * Send to socket * * @param string $msg */ public function send($msg, $timeout = null) { if (is_null($timeout)) { $secs = null; $usecs = null; } elseif ($timeout == 0) { $secs = 0; $usecs = 0; } else { $maximum = $timeout * self::MILLION; $usecs = $maximum % self::MILLION; $secs = floor(($maximum - $usecs) / self::MILLION); } $read = array(); $write = array($this->socket); $except = array(); $select = stream_select($read, $write, $except, $secs, $usecs); if ($select === false) { $this->log->log('ERROR sending message; reconnecting.'); $this->doReconnect(); // TODO: retry send here return false; } elseif ($select > 0) { $this->log->log('Socket is ready, send it.', XMPPHP_Log::LEVEL_VERBOSE); } else { $this->log->log('Socket is not ready, break.', XMPPHP_Log::LEVEL_ERROR); return false; } $sentbytes = fwrite($this->socket, $msg); $this->log->log('SENT: ' . mb_substr($msg, 0, $sentbytes, '8bit'), XMPPHP_Log::LEVEL_VERBOSE); if ($sentbytes === false) { $this->log->log('ERROR sending message; reconnecting.', XMPPHP_Log::LEVEL_ERROR); $this->doReconnect(); return false; } $this->log->log('Successfully sent ' . $sentbytes . ' bytes', XMPPHP_Log::LEVEL_VERBOSE); return $sentbytes; }
/** * Send to socket * * @param string $msg */ public function send($msg, $rec = false) { if ($this->time() - $this->last_send < 0.1) { usleep(100000); } $wait = true; while ($wait) { $read = null; $write = array($this->socket); $except = null; $select = @stream_select($read, $write, $except, 0, 0); if ($select === False) { $this->doReconnect(); return false; } elseif ($select > 0) { $wait = false; } else { usleep(100000); //$this->processTime(.25); } } $sentbytes = @fwrite($this->socket, $msg, 1024); $this->last_send = $this->time(); $this->log->log("SENT: " . mb_substr($msg, 0, $sentbytes, '8bit'), XMPPHP_Log::LEVEL_VERBOSE); if ($sentbytes === FALSE) { $this->doReconnect(); } elseif ($sentbytes != mb_strlen($msg, '8bit')) { $this->send(mb_substr($msg, $sentbytes, mb_strlen($msg, '8bit'), '8bit'), true); } }
/** * Send to socket * * @param string $msg */ public function send($msg, $timeout = NULL) { if (is_null($timeout)) { $secs = NULL; $usecs = NULL; } else { if ($timeout == 0) { $secs = 0; $usecs = 0; } else { $maximum = $timeout * 1000000; $usecs = $maximum % 1000000; $secs = floor(($maximum - $usecs) / 1000000); } } $read = array(); $write = array($this->socket); $except = array(); $select = @stream_select($read, $write, $except, $secs, $usecs); if ($select === False) { $this->log->log("ERROR sending message; reconnecting."); $this->doReconnect(); # TODO: retry send here return false; } elseif ($select > 0) { $this->log->log("Socket is ready; send it.", XMPPHP_Log::LEVEL_VERBOSE); } else { $this->log->log("Socket is not ready; break.", XMPPHP_Log::LEVEL_ERROR); return false; } $sentbytes = @fwrite($this->socket, $msg); $this->log->log("SENT: " . mb_substr($msg, 0, $sentbytes, '8bit'), XMPPHP_Log::LEVEL_VERBOSE); if ($sentbytes === FALSE) { $this->log->log("ERROR sending message; reconnecting.", XMPPHP_Log::LEVEL_ERROR); $this->doReconnect(); return false; } $this->log->log("Successfully sent {$sentbytes} bytes.", XMPPHP_Log::LEVEL_VERBOSE); return $sentbytes; }
public function testExplicitPrintoutLevel() { $log = new XMPPHP_Log(false, XMPPHP_Log::LEVEL_ERROR); $msg = 'I am a test log message'; ob_start(); $log->log($msg); $result = ob_get_clean(); $this->assertSame('', $result); ob_start(); $log->printout(true, XMPPHP_Log::LEVEL_INFO); $result = ob_get_clean(); $this->assertSame('', $result); }