本文整理汇总了PHP中socket_shutdown函数的典型用法代码示例。如果您正苦于以下问题:PHP socket_shutdown函数的具体用法?PHP socket_shutdown怎么用?PHP socket_shutdown使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了socket_shutdown函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __destruct
public function __destruct()
{
if (true === $this->isConnected()) {
socket_shutdown($this->socket);
socket_close($this->socket);
}
}
示例2: refresh_user
function refresh_user($discord_id)
{
global $socket, $error;
$so = socket_create(AF_UNIX, SOCK_DGRAM, 0);
if ($so === false) {
$msg = socket_strerror(socket_last_error());
$error = "Socket failed: {$msg}";
} else {
$res = socket_connect($so, $socket);
if ($res === false) {
$msg = socket_strerror(socket_last_error());
$error = "Connect failed: {$msg}";
} else {
$payload = json_encode(array('action' => 'refresh', 'user_id' => $discord_id));
$res = socket_write($so, $payload);
if ($res === false) {
$error = "Socket send failed";
} else {
if ($res < strlen($payload)) {
$error = "Socket did not send all data";
}
}
socket_shutdown($so);
socket_close($so);
}
}
}
示例3: closeSocket
/**
* Creates a new socket
* @return resource
*/
static function closeSocket($sock)
{
$ret_val = @socket_shutdown($sock, 2);
// Socket close doesn't return anything, so we return the result of socket_shutdown (boolean)
@socket_close($sock);
return $ret_val;
}
示例4: send_request
/**
* Send request to the daemon
*
* @param string $execute
* @return string Daemon answer
* @todo Remove error operator
*/
function send_request($execute)
{
// @$socket = socket_create (AF_INET, SOCK_STREAM, 0);
@($socket = socket_create(AF_UNIX, SOCK_STREAM, 0));
if ($socket < 0) {
$errno = "socket_create() failed.\n";
return $errno;
}
// @$result = socket_connect ($socket, '127.0.0.1', 9876);
@($result = socket_connect($socket, EasyConfig::$cfg->SOCK_EASYSCPD));
if ($result == false) {
$errno = "socket_connect() failed.\n";
return $errno;
}
// read one line with welcome string
socket_read($socket, 1024, PHP_NORMAL_READ);
// $out = read_line($socket);
// send reg check query
// $query = $execute . "\r\n";
$query = trim($execute) . "\n";
socket_write($socket, $query, strlen($query));
// read answer from the daemon
$out = socket_read($socket, 10240, PHP_NORMAL_READ);
socket_shutdown($socket, 2);
socket_close($socket);
// sleep(1);
// todo: prüfen ob das noch benötigt wird. Wenn keine Fehler mehr auftreten kann es entfernt werden
// usleep(250);
return trim($out);
}
示例5: send
/**
* Method send
*
* @param string $raw_text
*
* @return string $return_text
*/
public function send($raw_text)
{
if (!empty($raw_text)) {
$this->raw_text = $raw_text;
$xw = new xmlWriter();
$xw->openMemory();
$xw->startDocument('1.0');
$xw->startElement('wordsegmentation');
$xw->writeAttribute('version', '0.1');
$xw->startElement('option');
$xw->writeAttribute('showcategory', '1');
$xw->endElement();
$xw->startElement('authentication');
$xw->writeAttribute('username', $this->username);
$xw->writeAttribute('password', $this->password);
$xw->endElement();
$xw->startElement('text');
$xw->writeRaw($this->raw_text);
$xw->endElement();
$xw->endElement();
$message = iconv("utf-8", "big5", $xw->outputMemory(true));
//send message to CKIP server
set_time_limit(60);
$protocol = getprotobyname("tcp");
$socket = socket_create(AF_INET, SOCK_STREAM, $protocol);
socket_connect($socket, $this->server_ip, $this->server_port);
socket_write($socket, $message);
$this->return_text = iconv("big5", "utf-8", socket_read($socket, strlen($message) * 3));
socket_shutdown($socket);
socket_close($socket);
}
return $this->return_text;
}
示例6: unlock
/**
*
* @unlock
*
* @description
* - unlock the port
*
* @parameters
* -
*
* @return
* -
*
*/
public function unlock()
{
//free
@socket_shutdown($this->_Sock, 2);
@socket_close($this->_Sock);
debug("unlock() :: Try to reset the port! [{$this->_Port}] ");
}
示例7: init
public function init()
{
if (!($sock = socket_create(AF_INET, SOCK_STREAM, 0))) {
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Couldn't create socket: [{$errorcode}] {$errormsg} \n");
}
echo "Socket created \n";
//Connect socket to remote server
if (!socket_connect($sock, self::ADDRESS, self::PORT)) {
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not connect: [{$errorcode}] {$errormsg} \n");
}
echo "Connection established \n";
$message = json_encode(['message' => 'Alright!']);
//Send the message to the server
if (!socket_send($sock, $message, strlen($message), 0)) {
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not send data: [{$errorcode}] {$errormsg} \n");
}
echo "Message send successfully \n";
//Now receive reply from server
if (socket_recv($sock, $buf, 2045, MSG_WAITALL) === FALSE) {
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not receive data: [{$errorcode}] {$errormsg} \n");
}
//print the received message
socket_shutdown($sock);
return $buf;
}
示例8: close
public function close() {
if ($this->connected) {
socket_shutdown($this->socket);
socket_close($this->socket);
$this->socket = null;
}
}
示例9: refreshDiscordId
private function refreshDiscordId($discordId)
{
$options = XenForo_Application::get('options');
if ($options->botSocket === '') {
return;
}
XenForo_Error::debug("Refreshing user {$discordId}");
$so = socket_create(AF_UNIX, SOCK_DGRAM, 0);
if ($so === false) {
$msg = socket_strerror(socket_last_error());
$error = "Bot socket create failed: {$msg}";
throw new Exception($error);
}
$res = socket_connect($so, $options->botSocket);
if ($res === false) {
$msg = socket_strerror(socket_last_error());
$error = "Bot socket connect failed: {$msg}";
throw new Exception($error);
}
$payload = json_encode(array('action' => 'refresh', 'user_id' => $discordId));
$res = socket_write($so, $payload);
socket_shutdown($so);
socket_close($so);
if ($res === false) {
$error = "Bot socket send failed";
throw new Exception($error);
} else {
if ($res < strlen($payload)) {
// This will probably never happen.
$error = "Bot socket did not send all data";
throw new Exception($error);
}
}
}
示例10: disconnect
/**
* @return bool
*/
public function disconnect()
{
if ($this->connection === null) {
return true;
}
return socket_shutdown($this->connection);
}
示例11: CloseClient
public static function CloseClient($Client)
{
if ($Client != Null) {
@socket_shutdown($Client, 2);
//Schließe den Socket in beiden Richtungen
socket_close($Client);
}
}
示例12: disconnect
public function disconnect()
{
if (!$this->usingProxy) {
socket_shutdown($this->resSocket);
} else {
unset($this->proxyObject);
}
}
示例13: close
public function close()
{
if (is_resource($this->socket)) {
@socket_shutdown($this->socket, 2);
@socket_close($this->socket);
}
$this->disconnected = true;
}
示例14: disconnect
public function disconnect()
{
if (@socket_shutdown($this->sock, 2) == FALSE) {
return aff_error(socket_strerror(socket_last_error()));
}
socket_close($this->sock);
aff_ok("Closing connection client " . $this->id . " on server : " . $this->host . ":" . $this->port . " succeed.");
}
示例15: close
public function close()
{
if (is_resource($this->socket)) {
@socket_shutdown($this->socket, 2);
@socket_close($this->socket);
}
$this->socket = (int) $this->socket;
}