note 123992 added to function.socket-set-option
| From: | gmailuserasmqb7@php.net | Date: | Sat, 29 Jun 2019 05:31:00 +0000 |
| Subject: | note 123992 added to function.socket-set-option | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-211401@lists.php.net to get a copy of this message | ||
PLEASE NOTE
PHP 7.3.6, and probably many previous versions, automatically sets SO_REUSEADDR when you use
stream_socket_server().
php_network_bind_socket_to_local_addr() is called at https://github.com/php/php-src/blob/623911f993f39ebbe75abe2771fc89faf6b15b9b/main/streams/xp_socket.c#L675
and defined at https://github.com/php/php-src/blob/61a6a6ec51297506c54f3c6e60ace9b892d0a3e4/main/network.c#L401
and if you take a look you'll see
#ifdef SO_REUSEADDR
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char*)&sockoptval, sizeof(sockoptval));
#endif
I initially thought I'd need to play with context options to turn this on, but no, the simplest
single-arg call with no error checking and just an address, works for me.
strace your PHP binary to be 100% sure:
...
setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
...
The chances are you ARE using SO_REUSEADDR unless you're using a 100-year old UNIX clone in a
month with a Z in it.
----
Server IP: 208.43.231.9
Probable Submitter: 101.0.109.162 (proxied: 58.166.84.80)
----
Manual Page -- http://php.net/manual/en/function.socket-set-option.php
Edit -- https://master.php.net/note/edit/123992
Del: integrated -- https://master.php.net/note/delete/123992/integrated
Del: useless -- https://master.php.net/note/delete/123992/useless
Del: bad code -- https://master.php.net/note/delete/123992/bad+code
Del: spam -- https://master.php.net/note/delete/123992/spam
Del: non-english -- https://master.php.net/note/delete/123992/non-english
Del: in docs -- https://master.php.net/note/delete/123992/in+docs
Del: other reasons-- https://master.php.net/note/delete/123992
Reject -- https://master.php.net/note/reject/123992
Search -- https://master.php.net/manage/user-notes.php