User Datagram Protocol (UDP)

UDP, or User Datagram Protocol, is a core communication protocol used on the Internet, alongside TCP.

UDP is connectionless: UDP does not establish a connection before sending data. It simply sends packets, called datagrams, to the destination without checking if the recipient is ready or available.

UDP is fast and lightweight: because it skips the handshake and error-checking steps, UDP is faster and uses fewer resources than TCP.

UDP is unreliable: UDP does not guarantee delivery, order, or error correction. Packets may be lost, duplicated, or arrive out of order.

UDP is often associated, or opposed to TCP.

In PHP, UDP is supported through socket programming. PHP provides functions to create, bind, send, and receive UDP datagrams using the ext/socket extension.

<?php

    // Create a UDP socket
    $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);

    if ($socket === false) {
        $error = socket_last_error();
        die('socket_create() failed: ' . socket_strerror($error));
    }

    echo "UDP socket created successfully.\n";

?>

Documentation

See also Building a UDP Server, Gaming Client, and Tic-Tac-Toe Game with PHP and Using PHP To Send A UDP Message.

Related : TCP, Internet Protocol (IP), Port, Socket