for creating sockets you need methods like [man]fsockopen[/man].
To accept socket connections using [man]socket_accept[/man] it makes sense only when you are using PHP CLI.
[man]socket_getpeername[/man] will give you the remote IP address, while [man]socket_getsockname[/man] will give you the local IP address (useful when a machine has multiple IP addresses).