How does PHP collect socket data? 20

Updated on technology 2024-06-04
3 answers
  1. Anonymous users2024-02-11

    Send data.

    The function send will only send data, it needs the socket descriptor, the data being sent and its size.

    message = "get / http/";if(!socket_send($socket,$message,strlen($message),0)){

    errorcode = socket_last_error();

    errormsg = socket_strerror($errorcode);

    die("send failed !");

    The message is actually an http command to get the home page.

    Note] When sending data to a socket, you are basically writing data to the socket similar to writing data to a file, so you can also use the write function to send data to the socket.

    Receive data. Use the recv function to receive data on the socket.

    if(socket_recv($socket,$buf,2045,msg_waitall) === false){

    errorcode = socket_last_error();

    errormsg = socket_strerror($errorcode);

    die("receive failed !");

    echo $buf;

    Turn off the socket

    socket_close($socket);

  2. Anonymous users2024-02-10

    PHP does not support WebSockets

    But you can find an extension that doesn't have a websocket.

    In addition, you can consider using JS to connect to the other party's websocket, and pass the data to PHP through AJAX after obtaining the data. This will have a problem, how does PHP tune JS? If you use the web mode, it's relatively simple, but if you use the CLI mode, you can't think of any way to use it.

  3. Anonymous users2024-02-09

    In the process of using PHP for data collection, it is common to encounter the situation that the IP address is blocked or a verification code appears; In order to be able to continue the collection, we need to switch between different IPs, and each time we visit, we will switch one IP at random. Of course, you can also collect a large number of ** and collect ** by switching **, and the principle is about the same.

    Because I encountered this situation in my actual work, the scene that happened happened was the server of the US station group, which has been bound to more than 200 IPs (this kind of server is 1300 yuan a month), so you can easily use the socket bind() function to bind the export IP, and you only need to randomly select an IP for binding.

Related questions
10 answers2024-06-04

3.Configure collection rules. You can use the intelligent recognition function to let Octopus automatically identify the data structure of the e-commerce ** page, or manually set the collection rules. >>>More

13 answers2024-06-04

There are a lot of web collection tools,But it's generally more difficult to use.,Can't write a program to estimate it.,There's a newly released octopus collector recently.,It's pretty simple.,It's a little bit of a mouse.。

9 answers2024-06-04

For most manufacturing enterprises, the automatic data acquisition of measuring instruments has always been a troublesome thing, even if the instrument has RS232 485 and other interfaces, but still in the use of measurement, while manually recording to the paper, and finally input into the PC to process the way, not only the work is heavy, but also can not ensure the accuracy of the data, often the data obtained by the management personnel has been lagging behind the data for a day or two; For on-site defective product information and related output data, how to achieve efficient, concise and real-time data collection is a major problem.

7 answers2024-06-04

The opening of the topic is the purpose and significance of the topic. >>>More

15 answers2024-06-04

You put $mysql=mysql query("select * from user where name='$name'");Change to $mysql=mysql query("select * from user where name='”.$name."'");Then print it in the update file to see if there is a value. >>>More