1

I want to send something to my connected clients over another php script. But when I use the function "send", clientlist is null. Can you help me about this please?

Socket.php:

$clientlist = array();

function run() {
    global $clientlist;

    set_time_limit(0);
    $address = '127.0.0.1';
    $port = 80;
    $sock = socket_create(AF_INET, SOCK_STREAM, 0); 

    socket_bind($sock, 0, $port) or die('Could not bind to address'); 
    socket_listen($sock);

    printf("Listening...\r\n");

    while (true) {
        $client = socket_accept($sock);
        $input = socket_read($client, 1024000);

        $clientlist[] = $client;
    }
}

function send($msg) {
    global $clientlist;
    printf("Count: " . count($clientlist) . "\r\n");
    socket_write($clientlist[0], "Hey");
}

Msg.php:

include("socket.php");

send($_GET['msg']);
Gubi123
  • 11
  • 1
  • I don't think that's possible. But you could have a main server that stores all the connected clients and use that server to pass data between clients. – t.m.adam Mar 26 '19 at 06:53

0 Answers0