0

I have a socket server that breaks on some incoming connection requests (it stalls on those requests for exactly one minute on stream_socket_accept() although default_socket_timeout is 10s).

Is there any way to get the IP address of the client before doing stream_socket_accept()?

Are there server logs that would give insight on what is happening in a deeper level when somebody pings any given port on the server?

Maybe that way I could track this issue down.

Armin Hierstetter
  • 1,078
  • 2
  • 12
  • 27

1 Answers1

1

You cannot get the remote IP address before accepting the connection. You have to use a firewall instead.

You could either use stream_socket_get_name(socket, true) after stream_socket_accept or use the 3-parameter version of stream_socket_accept, which lets you set a timeout and returns the remote IP.

  • Are you sure? Because I have not yet called stream_socket_accept yet, so I do not have the socket I could call stream_socket_get with, huh? – Armin Hierstetter Jul 15 '16 at 07:01
  • Actually you can't get the remote IP address before acception the connection. If you need to, you have to use a firewall. See also: [link](http://stackoverflow.com/questions/6418603/linux-tcp-server-reading-clients-ip-address-before-accepting-connection). – Wolfgang Loch Aug 02 '16 at 13:18
  • @ArminHierstetter or you pretty much need your own TCP stack... stream_socket_accept() is really just creating a file descriptor to the socket in the calling program and removes it from the backlog. The actual SYN/ACK sending happens transparently in kernel before the _accept()_ syscall. – bwoebi Aug 02 '16 at 13:31
  • @bwoebi thanks for this. The problem has been solved. The script did not take into account that php.ini setting have no effect on scripts called from the shell. ini_set did the trick and solved the underlying problem. – Armin Hierstetter Aug 03 '16 at 14:08