note 126870 added to function.socket-bind

From: Date: Tue, 22 Feb 2022 12:25:47 +0000
Subject: note 126870 added to function.socket-bind
Groups: php.notes 
Request: Send a blank email to php-notes+get-217643@lists.php.net to get a copy of this message
I am posting this as I've spent a few hours debugging this. If you use socket_create / socket_bind with Unix domain sockets, then using socket_close at the end is not sufficient. You will get "address already in use" the second time you run your script. Call unlink on the file that is used for Unix domain sockets, preferably before you start to create the socket. <?php $socket_file = "./test.sock"; if (file_exists($socket_file)) unlink($socket_file); # optional file lock $socket = socket_create(AF_UNIX, SOCK_STREAM, 0); # ... socket_set_option ... socket_bind($socket, $socket_file); # ... socket_close($socket); # optional : release lock unlink($socket_file); ?> ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.135 (proxied: 82.78.175.39) ---- Manual Page -- https://php.net/manual/en/function.socket-bind.php Edit -- https://main.php.net/note/edit/126870 Del: integrated -- https://main.php.net/note/delete/126870/integrated Del: useless -- https://main.php.net/note/delete/126870/useless Del: bad code -- https://main.php.net/note/delete/126870/bad+code Del: spam -- https://main.php.net/note/delete/126870/spam Del: non-english -- https://main.php.net/note/delete/126870/non-english Del: in docs -- https://main.php.net/note/delete/126870/in+docs Del: other reasons-- https://main.php.net/note/delete/126870 Reject -- https://main.php.net/note/reject/126870 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#217643) next »