L
L
lemonable2022-01-22 18:54:48
linux
lemonable, 2022-01-22 18:54:48

Why is php not sending a UDP packet to the server?

There is a simple script

<?php
$server_ip   = $_POST['host'];
$server_port = $_POST['port'];

echo "Sending heartbeat to IP $server_ip, port $server_port\n";

if ($socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP)) {
  for ($i = 1; $i <= 10; $i++) {
    $send_socket = socket_sendto($socket, $message, strlen($message), 0, $server_ip, $server_port);
    
    if($send_socket !== 0){
        echo "Сокет не отправлен.";
        var_dump($send_socket);
    }else{
        echo "Успеншо отправлен сокет";
    }

    sleep(1);
  }
} else {
  echo "Can't create socket";
}

The script works, I ran it on my computer, I send the UDP packet to the VPS, I check if the packets arrive in it with the command tcpdump -n udp port 4444
The same if done on a clean VPS, on which ubuntu20.04 and php7.4-fpm, the packets are sent to the server.

But if the script is run on some third-party server, UDP packets are not sent for some reason, socket_sendto returns bool(false), I also tested sending a UDP packet in C language, everything is the same for some reason, packets are not sent on third-party servers, what there may be a problem, please tell me.
I mean a third-party server, for example, hosting or just a VPS on which there is an admin panel for its administration.
Maybe the firewall prohibits sending packets or some rights are missing.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Karabanov, 2022-01-23
@lemonable

Check the firewall settings, both on the VPS and in the hosting panel, on the page where the network connection is configured (if any) - you need to make sure that traffic is allowed to pass through this port.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question