|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-01-02 19:23 UTC] piotr at t-p-l dot com
sample code: (not complete .. just gives the idea)
///////////////
$Domain = // either AF_UNIX or AF_INET
$result = socket_accept($sock);
$address = "<undefined>";
$port = "<undefined>";
if ($Domain == AF_UNIX) {
socket_getpeername($result,$address,$port);
echo "Accepted Connection from: $address\n";
} else { // its AF_INET
socket_getpeername($result,$address,$port);
echo "Accepted Connection from: $address:$port\n";
}
///////////////
when the socket is a AF_INET socket the result if properly filled in. sample output:
Accepted Connection from: 123.123.123.123:1234
but when the socket is a unix socket .. the result is somehow wrong .. sample:
Accepted Connection from: $0
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 20 15:00:01 2025 UTC |
Here it goes .. <?php $sock = socket_create(AF_UNIX, SOCK_STREAM, 0); socket_bind($sock, "/tmp/mysock"); socket_listen($sock); $asock = socket_accept($sock); socket_getpeername($asock, $address, $port); echo "Connection from Address: $address Port: $port\n"; ?> the result (after connecting to the socket .. I used the utility "sock" to quickly connect to the socket) was the following: Connection from Address: ??0 Port: aka .. gibberish .. here is the result of php -v for your reference: PHP 4.3.0 (cli) (built: Jan 13 2003 01:39:49) Copyright (c) 1997-2002 The PHP Group Zend Engine v1.3.0, Copyright (c) 1998-2002 Zend Technologies