PHP.mk документација

socket_close

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

function.socket-close.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека function.socket-close.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
socket_close

Референца за `function.socket-close.php` со подобрена типографија и навигација.

function.socket-close.php

socket_close

(PHP 4 >= 4.1.0, PHP 5, PHP 7, PHP 8)

socket_closeЗатвора а Сокет instance

= NULL

socket_close(Сокет $socket): void

socket_close() го затвора Сокет инстанца дадена од socket.

Параметри

socket

А Сокет инстанца креирана со socket_create() or socket_accept().

Вратени вредности

Не се враќа вредност.

Дневник на промени

Верзија = NULL
8.0.0 socket е Сокет Врати ресурс или resource.

Види Исто така

Белешки од корисници 2 забелешки

yaBliznyk на gmail точка com
пред 8 години
/* any code */
$linger = array ('l_linger' => 0, 'l_onoff' => 1);
socket_set_option($socket, SOL_SOCKET, SO_LINGER, $linger);
socket_close($sock);

This is code to force close socket connection.
aeolian meson на NOSPAM dot blitzeclipse dot com
19 години пред
PHP: 5.1.4
Summary: close() does not relinquish socket immediately.

With the BSD socket implementation (which is the socket interface used by PHP), a socket_close() may close the socket, but there may yet be data to send. Until the data is sent, the port will not be available. Therefore, all further bindings attempted on that port will not be acceptable due to the 'port can not be reused' (the approximate message, anyway) error. Ordinarily, if the REUSABLE socket option is set, the only thing that will raise such an error is a binding to a specific IP/PORT combination that is already bound.

To avoid this problem, you must tell it to delay returning until the port either sends the rest of its data, or times-out in doing it. This is done via the SO_LINGER option. To set this option, it requires an array of two elements: the first indicates whether a linger is required on any data before the shutdown completes, and the second indicates whether we actually linger. If we set a nonzero to the first while setting a zero to the second, we would simply drop whatever data is waiting in the buffer, and close the socket. To tell it simply to wait on the data to be sent, you send a non-zero for both: array(1, 1).

Note that if you have indicated not to block (socket_set_nonblock()), it will simply exit no matter what, much like it usually would. In this case it bursts an EWOULDWAIT flag, but since I don't think we have access to these socket flags in PHP, one should re-enable blocking right before they set the linger and quit.

    // These commands get fed straight through to the Unix socket libraries.. That's why they're a little more C-like.
    $arrOpt = array('l_onoff' => 1, 'l_linger' => 1);
    socket_set_block($this->Socket);
    socket_set_option($this->Socket, SOL_SOCKET, SO_LINGER, $arrOpt);
    socket_close($this->Socket);
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.