PHP Socket I / O Methods

What is the preferred method for reading / writing TCP / IP sockets in PHP? There are many, many ways to do this, including:

  • fread() and fwrite()
  • fgets() and fputs()
  • file_get_contents() and file_put_contents()
  • stream_get_contents()
  • stream_socket_recvfrom() and stream_socket_sendto()
  • perhaps a few others that I have not come across ...

I understand that fgets()they fputs()work a bit differently (in rows instead of arbitrary pieces of data), but I really do not understand the differences in others and which method is best suited for what purpose.

Edit: Also socket_recv()and socket_send().

Edit # 2: Also socket_read()and socket_write().

+5
source share

All Articles