search

Home  >  Q&A  >  body text

Can PHP control communication with IoT devices through Socket?

After searching on the Internet, I saw that there are many Socket-related functions in PHP. The usage process is:

socket_create
socket_bind
socket_listen
socket_accept
socket_read
socket_write
socket_close

However, what I don’t understand the most is the socket_accept step. To be used via while (true) {} infinite loop.

Is it possible to execute PHP files only through the CLI command line?

In addition, it seems easier to receive and send information to the server on the client side, but how can the server receive and send information to the client at will? (Instead of just receiving and sending once in the loop statement and then closing the socket object like the online examples.

高洛峰高洛峰2824 days ago723

reply all(5)I'll reply

  • 大家讲道理

    大家讲道理2017-05-16 13:13:41

    Using swoole is very good
    We have already used it on WeChat mini programs

    reply
    0
  • 阿神

    阿神2017-05-16 13:13:41

    The websocket in the php swoole extension can realize real-time communication function

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-16 13:13:41

    Preferred swoole

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-16 13:13:41

    What is Workerman
    Workerman is an open source high-performance PHP socket server framework developed purely in PHP. It is widely used in the development of mobile apps, mobile communications, WeChat applets, mobile game servers, online games, PHP chat rooms, hardware communications, smart homes, Internet of Vehicles, Internet of Things and other fields. Supports TCP long connections, supports Websocket, HTTP and other protocols, and supports custom protocols. It has many high-performance components such as asynchronous Mysql, asynchronous Redis, asynchronous Http, asynchronous message queue, etc.

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-16 13:13:41

    workerman or swoole are both acceptable.

    reply
    0
  • Cancelreply