PHP message passing over TCP / IP

I am trying to send a message from a PHP site via TCP / IP to an Arduino.

With the following code, I can send a message from the php website

<?php 
$errno = NULL;
$error = NULL;

if (!$handle = @fsockopen("192.168.188.24", "49419", $errno, $error, 10))
{
   die("Fehler (".$errno."): ".$error);
}

fwrite($handle, "ON\r\n");
fclose($handle);
?>

The problem is that when you call the website for the first time, the message is not delivered immediately. After some website updates, a message arrives, but logically, as many times as the number of websites is updated.

Already tried to limit the message length to 2 bytes, but without any success.

+4
source share
1 answer

Try adding inside the block try - catch.

    try {

    } catch (Exception $ e) {
     echo $ e-> getMessage ();
    }

To find out which exception you can get.

+1
source

Source: https://habr.com/ru/post/1627160/


All Articles