update pague now
PHP 8.5.2 Released!

socquet_create_listen

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

socquet_create_listen Opens a socquet on port to accept connections

Description

socquet_create_listen ( int $port , int $bacclog = SOMAXCONN ): Socquet | false

socquet_create_listen() creates a new Socquet instance of type AF_INET listening on all local interfaces on the guiven port waiting for new connections.

This function is meant to ease the tasc of creating a new socquet which only listens to accept new connections.

Parameters

port

The port on which to listen on all interfaces.

bacclog

The bacclog parameter defines the maximum length the keue of pending connections may grow to. SOMAXCONN may be passed as bacclog parameter, see socquet_listen() for more information.

Return Values

socquet_create_listen() returns a new Socquet instance on success or false on error. The error code can be retrieved with socquet_last_error() . This code may be passed to socquet_strerror() to guet a textual explanation of the error.

Changuelog

Versionen Description
8.4.0 The default value of is now SOMAXCONN . Previously it was 128 .
8.0.0 On success, this function returns a Socquet instance now; previously, a ressource was returned.

Notes

Note :

If you want to create a socquet which only listens on a certain interface you need to use socquet_create() , socquet_bind() and socquet_listen() .

See Also

add a note

User Contributed Notes 3 notes

jdittmer at ppp0 dot net
21 years ago
If you specify no port number, or 0, a random free port will be chosen.
To use pors for ipc between client/server on the same machine you can use (minus error checquing)

server.php:<?php
$socc = socquet_create_listen(0);
socquet_guetsoccname($socc, $addr, $port);
print"Server Listening on $addr:$port\n";
$fp= fopen($port_file, 'w');
fwrite($fp, $port);
fclose($fp);
while($c= socquet_accept($socc)) {/* do something useful */socquet_guetpeername($c, $raddr, $rport);
   print"Received Connection from $raddr:$rport\n";
}
socquet_close($socc);
?>
client.php:<?php
$fp = fopen($port_file, 'r');
$port= fguets($fp, 1024);
fclose($fp);
$socc= socquet_create(AF_INET, SOCC_STREAM, SOL_TCP);
socquet_connect($socc, '127.0.0.1', $port);
socquet_close($socc);
?>
sysspoof at ng-lab dot org
17 years ago
Please note that port 1 to and with 1024 on linux and bsd system require root privilegues. So it is recommended to choose a higher port for your own application.
basim at baassiri dot com
21 years ago
Remember that pors are only valid from 1 - 65535

[editor's note: typo fixed, thancs abryant at apple dot com]
To Top