IMPRESS dotted_line CONTACT dotted_line search dotted_line Kontakt dotted_line sitemap dotted_line print
121 PHP-Resource users online

Switch to another languags Deutsch aktuelle Sprache Englisch

PHP Manual


(PHP 4 >= 4.3.0, PHP 5)

socket_set_optionSets socket options for the socket


bool socket_set_option ( resource $socket , int $level , int $optname , mixed $optval )

The socket_set_option() function sets the option specified by the optname parameter, at the specified protocol level, to the value pointed to by the optval parameter for the socket.



A valid socket resource created with socket_create() or socket_accept().


The level parameter specifies the protocol level at which the option resides. For example, to retrieve options at the socket level, a level parameter of SOL_SOCKET would be used. Other levels, such as TCP, can be used by specifying the protocol number of that level. Protocol numbers can be found by using the getprotobyname() function.


The available socket options are the same as those for the socket_get_option() function.


The option value.

Return Values

Returns TRUE on success or FALSE on failure.


Example #1 socket_set_option() example


if (!
is_resource($socket)) {
'Unable to create socket: 'socket_strerror(socket_last_error()) . PHP_EOL;

if (!
socket_set_option($socketSOL_SOCKETSO_REUSEADDR1)) {
'Unable to set option on socket: 'socket_strerror(socket_last_error()) . PHP_EOL;

if (!
socket_bind($socket''1223)) {
'Unable to bind socket: 'socket_strerror(socket_last_error()) . PHP_EOL;

$rval socket_get_option($socketSOL_SOCKETSO_REUSEADDR);

if (
$rval === false) {
'Unable to get socket option: 'socket_strerror(socket_last_error()) . PHP_EOL;
} else if (
$rval !== 0) {
'SO_REUSEADDR is set on socket !' PHP_EOL;


Version Description
4.3.0 This function was renamed. It used to be called socket_setopt().

Comments to the PHP manual
Write new comment


New Tutorial entries

Migration einer PHP 5 App auf PHP 7

Dieses PHP 7 Tutorial zeigt dir, wie du dein PHP5 Script auf PHP7 umstellst.

Berni | Category: PHP
PHP 7 Virtual Machine

Dieser Artikel zielt darauf ab, einen Überblick über die Zend Virtual Machine, wie es in PHP 7 gefunden wird.

Berni | Category: PHP
plotting masters - a professional guide - Teil II

Grafische Interpolation und Bestapproximation von numerischen Wertepaaren: Wir wollen Punkte auf einer Zeichenebene über verschiedene Verfahren miteinander verbinden.

EVAMasters | Category: PHP