Php Sockets vs Streams

后端 未结 2 1778
别那么骄傲
别那么骄傲 2021-01-30 09:36

I think php sockets and php streams are overlapping each other.
I\'ve managed to make a CLI PHP chat client and a server, using either sockets or streams.

Here som

2条回答
  •  闹比i
    闹比i (楼主)
    2021-01-30 09:57

    As you pointed out, 'streams' are in PHP core (built-in, always available) while 'sockets' are part of a rarely included extension. Other than that, they are nearly identical. You can use both TCP and UDP with streams with both as well as blocking and non-blocking modes, which covers 99% of all use-cases.

    The only common exception I can think of is ICMP. For example, 'ping'. However, it looks like there currently isn't a safe way to do ICMP from PHP. Such calls require SOCK_RAW via the socket extension, which requires 'root' privileges to execute. Also, not all routers will route other packet types outside of TCP, UDP, and ICMP. This limits the usefulness of the socket extension.

提交回复
热议问题