本文整理汇总了PHP中socket_clear_error函数的典型用法代码示例。如果您正苦于以下问题:PHP socket_clear_error函数的具体用法?PHP socket_clear_error怎么用?PHP socket_clear_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了socket_clear_error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: socketClose
public function socketClose()
{
$this->sock_error = socket_strerror(socket_last_error($this->fsock));
socket_clear_error();
@socket_close($this->fsock);
return $this;
}
示例2: get_mesh_info
private function get_mesh_info($info_type)
{
$socket = null;
try {
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
socket_clear_error($socket);
return null;
}
$result = socket_connect($socket, "127.0.0.1", 9090);
if ($result === false) {
socket_clear_error($socket);
return null;
}
$input = "GET /{$info_type} HTTP/1.1\r\n";
$output = '';
socket_write($socket, $input, strlen($input));
while ($buffer = socket_read($socket, 2048)) {
$output .= $buffer;
}
socket_close($socket);
return json_decode($output, true);
} catch (Exception $e) {
socket_clear_error($socket);
return null;
}
}
示例3: _connect
private function _connect()
{
if ($this->connection = socket_create($this->socket_domain, SOCK_STREAM, $this->socket_domain > 1 ? getprotobyname('tcp') : 0)) {
if (socket_connect($this->connection, $this->socket_address, $this->socket_port)) {
$this->setNonBlock();
// $this->connection); // устанавливаем неблокирующий режим работы сокета
return $this->connected = true;
} else {
$error = socket_last_error($this->connection);
socket_clear_error($this->connection);
switch ($error) {
case SOCKET_ECONNREFUSED:
case SOCKET_ENOENT:
// если отсутствует файл сокета, либо соединиться со слушающим сокетом не удалось - возвращаем false
$this->disconnect();
return false;
default:
// в иных случаях кидаем необрабатываемое исключение
throw new \Exception(socket_strerror($error));
}
}
}
// @TODO delete next line...
trigger_error('Client connect failed', E_USER_ERROR);
return false;
}
示例4: handleError
/**
* Handle socket errors.
*
* @return void
*
* @throws SyslogException if a socket error occured.
*/
protected function handleError()
{
if (\is_resource($this->sock) && socket_last_error($this->sock)) {
$e = new SyslogException(socket_strerror(socket_last_error($this->sock)), socket_last_error($this->sock));
socket_clear_error($this->sock);
throw $e;
}
}
示例5: check_sock_error
function check_sock_error($area)
{
$err = socket_last_error();
if ($err > 0) {
errorlog("CHECK_SOCK_ERROR(" . $area . "): " . socket_strerror(socket_last_error()));
socket_clear_error();
}
}
示例6: destructBot
public function destructBot($sMessage = false)
{
$this->Output('QUIT :' . ($sMessage == false ? $this->oMaster->oConfig->Network['quitmsg'] : $sMessage));
Timers::Delete($this->iPingTimer);
@socket_clear_error();
$this->socketShutdown();
$this->Active = false;
$this->isWaiting = false;
}
示例7: connect
/**
* Connect to Asterisk
* @param bool $reconfig
* @return boolean true on success
*/
public function connect($reconfig = false)
{
if ($reconfig && !$this->config->isChanged()) {
return true;
}
$this->reconnect = 0;
if ($this->socket) {
$this->reconnect = 1;
}
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === FALSE) {
$this->log("Unable to create socket - " . socket_last_error(), 'ERROR');
} else {
while (!@socket_connect($socket, $this->config->host, $this->config->port)) {
$this->log("Unable to connect to manager {$this->config->host}:{$this->config->port} - " . socket_last_error($socket), 'ERROR');
if ($this->reconnect && !$reconfig) {
usleep($this->reconnect_delay);
$this->fireEvent('Loop');
// if we got HUP here, we did connect() once more again, and it can be succeful
if (!$this->reconnect) {
return true;
}
} else {
$socket = FALSE;
break;
}
}
}
if ($socket !== FALSE) {
socket_clear_error($socket);
$this->log("Connected to manager {$this->config->host}:{$this->config->port}", 'DEBUG');
if ($this->reconnect) {
@socket_close($this->socket);
}
$this->socket = $socket;
$this->connected = 0;
$this->logged_in = 0;
$this->reconnect = 0;
$this->current_select_timeout = $this->handshake_timeout;
$this->config->clearChanged();
return true;
} else {
if ($reconfig) {
$this->log("Fail to change asterisk connection, keep working with old connection", 'ERROR');
}
return false;
}
}
示例8: error
function error($msg = null)
{
$errCode = socket_last_error($this->hnd);
if ($errCode != 0) {
//Connection reset by peer
if ($errCode == 104) {
$this->bConnected = false;
}
$errMsg = socket_strerror($errCode);
$this->sSocErr = "(" . $errCode . ")(" . $errMsg . ")";
socket_clear_error($this->hnd);
} elseif (strlen($msg)) {
$this->sSocErr = $errMsg;
}
return false;
}
示例9: sock_gets
function sock_gets($sock)
{
global $msgsock;
socket_clear_error($msgsock);
$buf = socket_read($sock, 4096, PHP_NORMAL_READ);
if (CITADEL_DEBUG_PROXY) {
syslog(LOG_DEBUG, "gets Read: " . $buf);
}
if (socket_last_error($sock)) {
return false;
}
if (preg_match("'\n\$'s", $buf)) {
$buf = substr($buf, 0, strpos($buf, "\n"));
}
return $buf;
}
示例10: __construct
public function __construct($message = null)
{
if (!$message) {
$errno = socket_last_error();
} elseif (is_resource($message)) {
$errno = socket_last_error($message);
} else {
parent::__construct((string) $message);
return;
}
$error = socket_strerror($errno);
parent::__construct($error, $errno);
if (!$message) {
socket_clear_error();
} else {
socket_clear_error($message);
}
}
示例11: connect
public function connect()
{
if ($this->is_connected()) {
return true;
}
if ($this->connection = socket_create($this->socket_domain, SOCK_STREAM, $this->socket_domain > 1 ? getprotobyname('tcp') : 0)) {
socket_set_option($this->connection, SOL_SOCKET, SO_REUSEADDR, true);
if (socket_bind($this->connection, $this->socket_address, $this->socket_port)) {
if (socket_listen($this->connection)) {
socket_set_nonblock($this->connection);
$this->_open_try = false;
// сбрасываем флаг попытки открыть сервер
return $this->opened = true;
} else {
throw new \Exception(socket_strerror(socket_last_error($this->connection)));
}
} else {
$error = socket_last_error($this->connection);
socket_clear_error($this->connection);
error_log('error: ' . $error);
switch ($error) {
case SOCKET_EADDRINUSE:
// если сокет уже открыт - пробуем его закрыть и снова открыть
// @TODO socket close self::socket_close();
// @todo recheck this code
// closing socket and try restart
$this->disconnect();
if (!$this->_open_try) {
$this->_open_try = true;
return $this->open();
}
break;
default:
throw new \Exception(socket_strerror($error));
}
}
}
// @TODO delete next line...
trigger_error('Server open failed', E_USER_ERROR);
return false;
}
示例12: send_udp_with_sock_lib
/**
* Sends a packet via UDP to the list of name servers.
*
* This function sends a packet to a nameserver. It is called by
* send_udp if the sockets PHP extension is compiled into PHP.
*
* @param string $packet A packet object to send to the NS list
* @param string $packet_data The data in the packet as returned by
* the Net_DNS_Packet::data() method
* @return object Net_DNS_Packet Returns an answer packet object
* @see Net_DNS_Resolver::send_tcp(), Net_DNS_Resolver::send(),
* Net_DNS_Resolver::send_udp(), Net_DNS_Resolver::send_udp_no_sock_lib()
*/
function send_udp_with_sock_lib($packet, $packet_data)
{
$retrans = $this->retrans;
$timeout = $retrans;
//$w = error_reporting(0);
$ctr = 0;
// Create a socket handle for each nameserver
foreach ($this->nameservers as $nameserver) {
if (($sock[$ctr++] = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP)) && socket_connect($sock[$ctr - 1], $nameserver, $this->port)) {
$peerhost[$ctr - 1] = $nameserver;
$peerport[$ctr - 1] = $this->port;
socket_set_nonblock($sock[$ctr - 1]);
} else {
$ctr--;
}
}
//error_reporting($w);
if ($ctr == 0) {
$this->errorstring = 'no nameservers';
return null;
}
// Try each nameserver up to $this->retry times
for ($i = 0; $i < $this->retry; $i++) {
if ($i != 0) {
// Set the timeout for each retry based on the number of
// nameservers there is a connected socket for.
$retrans *= 2;
$timeout = (int) ($retrans / $ctr);
}
// Make sure the timeout is at least 1 second
if ($timeout < 1) {
$timeout = 1;
}
// Try each nameserver
foreach ($sock as $k => $s) {
if ($this->debug) {
echo "\n;; send_udp(" . $peerhost[$k] . ':' . $peerport[$k] . '): sending ' . strlen($packet_data) . " bytes\n";
}
if (!socket_write($s, $packet_data)) {
if ($this->debug) {
echo ";; send error\n";
}
}
$set = array($s);
if ($this->debug) {
echo ";; timeout set to {$timeout} seconds\n";
}
$changed = socket_select($set, $w = null, $e = null, $timeout);
if ($changed) {
// Test to see if the connection was refused. Linux servers will send
// an ICMP message which will cause the client's next system call to
// return ECONNREFUSED if the server is not listening on the ip:port queried
if (socket_get_option($s, SOL_SOCKET, SO_ERROR) == SOCKET_ECONNREFUSED) {
// Unix socket connection was refused
if ($this->debug) {
echo ';; connection to ' . $peerhost[$k] . ':' . $peerport[$k] . " was refused\n";
}
// Try the next server.
continue;
}
// Read the response
$buf = @socket_read($s, 512);
if ($buf === false) {
// No data could be read from socket
if ($this->debug) {
echo ';; no data could be read from ' . $peerhost[$k] . ':' . $peerport[$k] . "\n";
echo ';; socket_error: ' . socket_strerror(socket_last_error()) . "\n";
}
// Reset the non-specific socket error status
socket_clear_error();
// Try the next server.
continue;
}
$this->answerfrom = $peerhost[$k];
$this->answersize = strlen($buf);
if ($this->debug) {
echo ';; answer from ' . $peerhost[$k] . ':' . $peerport[$k] . ': ' . strlen($buf) . " bytes\n";
}
$ans = new Net_DNS_Packet($this->debug);
if ($ans->parse($buf)) {
if ($ans->header->qr != '1') {
// Ignore packet if it is not a response
continue;
} elseif ($ans->header->id != $packet->header->id) {
// Ignore packet if the response id does not match the query id
continue;
} else {
//.........这里部分代码省略.........
示例13: handleSocketReadError
protected function handleSocketReadError()
{
$errno = socket_last_error($this->socket);
if ($errno === 11 || $errno === 35) {
throw new MongoCursorTimeoutException('Timed out waiting for data');
}
socket_clear_error($this->socket);
return socket_strerror($errno);
}
示例14: getRegSpamScore
static function getRegSpamScore(&$score, array $user, $verbose, $debug, $model)
{
$o = XenForo_Application::getOptions();
if (trim($o->TPUDetectSpamRegOpenPort) != '') {
if (!function_exists('socket_create')) {
$model->logScore('PHP function socket_create() not available, you need the PHP socket extension for open port detection to work', 0);
return;
}
$entries = array();
$socks = array();
foreach (explode("\n", $o->TPUDetectSpamRegOpenPort) as $entry) {
$entry = explode('|', trim($entry));
if (count($entry) != 2) {
continue;
}
list($points, $port) = $entry;
if (!is_numeric($port)) {
$port = getservbyname($port, 'tcp');
}
if ($port > 0) {
socket_clear_error();
if (self::isIPv6($user['ip'])) {
$sock = socket_create(AF_INET6, SOCK_STREAM, SOL_TCP);
} else {
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
}
socket_set_nonblock($sock);
@socket_connect($sock, $user['ip'], $port);
$errno = socket_last_error();
if ($errno == SOCKET_EALREADY || $errno == SOCKET_EINPROGRESS || $errno == 0) {
$socks[] = $sock;
} else {
socket_close($sock);
}
$entries[] = array('points' => $points, 'port' => $port, 'open' => false);
}
}
$start = microtime(true);
while ($socks && microtime(true) - $start < self::TIMEOUT) {
$null = null;
$write = $socks;
socket_select($null, $write, $null, 1);
foreach ($write as $k => $sock) {
$errno = socket_get_option($sock, SOL_SOCKET, SO_ERROR);
if ($errno == 0) {
$entries[$k]['open'] = true;
} elseif ($errno == SOCKET_ECONNREFUSED) {
} elseif ($errno == SOCKET_ETIMEDOUT) {
} else {
$errmsg = socket_strerror($errno);
}
unset($socks[$k]);
socket_close($sock);
}
}
foreach ($entries as $entry) {
if ($entry['open']) {
$model->logScore('tpu_detectspamreg_port_fail', $entry['points'], array('port' => $entry['port']));
$points = $entry['points'];
if (is_numeric($points)) {
$score['points'] += $points;
} else {
$score[$points] = true;
}
} else {
if ($debug) {
$model->logScore('tpu_detectspamreg_port_ok', 0, array('port' => $entry['port']));
}
}
}
}
}
示例15: set_error
/**
* 错误信息赋值
*/
protected function set_error()
{
$this->errCode = socket_last_error($this->sock);
$this->errMsg = socket_strerror($this->errCode);
socket_clear_error($this->sock);
}