How do I save the resource type in socket-PHP?

Source: Internet
Author: User
{Code ...}
I am currently writing a small project. I am only a front-end engineer and now I am writing a PHP script temporarily. The process is that the front-end sends data to the server, and the server sends data to the device through socket communication, and then sends the data from the device to the front-end in sequence. Currently, the data interaction function has been completed. However, one piece of data needs to be frequently sent from the device to the front-end, so we hope to keep the communication between the server and the device smooth at all times, in this way, you can avoid 'socket _ creat (), socket_connect () 'every time you send a message ()'. My initial thought was to save the created $ socket with session. However, it is found that the session cannot save the resource type. So I would like to ask you how to save the resource type, or how to avoid creating a socket for each message sending.

Reply content:
I am currently writing a small project. I am only a front-end engineer and now I am writing a PHP script temporarily. The process is that the front-end sends data to the server, and the server sends data to the device through socket communication, and then sends the data from the device to the front-end in sequence. Currently, the data interaction function has been completed. However, one piece of data needs to be frequently sent from the device to the front-end, so we hope to keep the communication between the server and the device smooth at all times, in this way, you can avoid 'socket _ creat (), socket_connect () 'every time you send a message ()'. My initial thought was to save the created $ socket with session. However, it is found that the session cannot save the resource type. So I would like to ask you how to save the resource type, or how to avoid creating a socket for each message sending.

The resource type cannot be saved. The resource type is just a reference, and the referenced object is meaningless if you save the reference.
Your requirements are not clear.Socket serverYou can use open-source solutions (suchWorkerman,SwooleOr write it by yourself.
The official website provides a simple example for reference:
Http://php.net/manual/zh/sockets.examples.php

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.