Just a quick note:
I found socket_getsockname() is not IPv6 compatible or may just return some unexpected results?
<?php
Simple Code Example:
$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
socket_bind($socket,'0.0.0.0',150);
socket_getsockname($socket, $IP, $PORT);
print $IP.":".$PORT."\n";
?>
This does not print $IP 127.0.0.1 or 192.168.1.1 or even 0.0.0.0 ... etc ... like you would expect ... in my case I receive 10.0.0.0 witch is not a valid port on my system using IPv5 and IPv6! Thus you should rely on using the initial values of socket_bind() to get the local address.
Hope this helps...
socket_getsockname
(PHP 4 >= 4.1.0, PHP 5)
socket_getsockname — Belirtilen soketin yerel tarafını sorgulayıp soket türüne göre ya bir konak/port çifti ya da bir Unix dosya yolu döndürür
Açıklama
$soket
, string &$adres
[, int &$port
] )Bilginize: socket_getsockname() işlevi socket_connect() ile oluşturulan
AF_UNIXsoketlerle kullanılmamalıdır. Sadece socket_accept() ile oluşturulan soketler ve socket_bind() çağrısından sonra bir birincil sunucu soketi için anlamlı bir değer döner.
Değiştirgeler
-
soket -
socket_create() veya socket_accept() ile oluşturulmuş geçerli bir soket özkaynağı.
-
adres -
Belirtilen soket
AF_INETveyaAF_INET6türündeyse socket_getsockname() işlevi, bu değiştirgede bir IP adresi (127.0.0.1 veya fe80::1 gibi) veportdeğiştirgesinde de belirtilmişse ilgili port numarasını döndürür.Belirtilen soket
AF_UNIXtüründeyse bu değiştirgede (/var/run/daemon.sock gibi) bir Unix dosya yolu döner. -
port -
Belirtilmişse ilgili port değeri bu değiştirgeye konur.
Dönen Değerler
Başarı durumunda TRUE, başarısızlık durumunda FALSE döner. Soket AF_INET,
AF_INET6 veya AF_UNIX türünde
değilse işlev FALSE döndürebilir, ancak böyle bir durumda son soket hata
kodu güncellenmez.
Ayrıca Bakınız
- socket_getpeername() - Belirtilen soketin yerel tarafını sorgulayıp soket türüne göre ya bir konak/port çifti ya da bir Unix dosya yolu döndürür
- socket_last_error() - Soket üzerindeki son hatanın kodunu döndürür
- socket_strerror() - Bir soket hatasıyla ilgili açıklamayı döndürür
