Creating a Simple Socket-Based Server : socket_create « Network « PHP






Creating a Simple Socket-Based Server

 
<?php
    set_time_limit(0);
    $address = "127.0.0.1";
    $port = 4545;

    $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

    socket_bind($socket, $address, $port);

    socket_listen($socket);
    $connection = socket_accept($socket);

    $result = trim(socket_read($connection, 1024));

    echo "Result received: '$result'\n";

    socket_close($connection);

    socket_shutdown($socket);
    socket_close($socket);
?>
  
  








Related examples in the same category

1.Domain Constants for Socket Connections
2.Socket Type Constants
3.Retrieving a Website Using Sockets