<?php$host = 'localhost';
$port = 7776;
$null = NULL;
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1);
socket_bind($socket, 0, $port);
socket_listen($socket);
$clients = array($socket);
while (true) {
$changed = $clients;
@socket_select($changed, $null, $null, 0, 10);
if (in_array($socket, $changed)) {
$socket_new = @socket_accept($socket);
$clients[] = $socket_new;
$header = socket_read($socket_new, 1024);
//perform_handshaking($header, $socket_new, $host, $port);
socket_getpeername($socket_new, $ip);
$found_socket = array_search($socket, $changed);
unset($changed[$found_socket]);
}
foreach ($changed as $changed_socket) {
while(@socket_recv($changed_socket, $buf, 1024, 0) >= 1)
{
//handle messages
}
$buf = @socket_read($changed_socket, 1024, PHP_NORMAL_READ);
//disconnect state
if ($buf === false) {
$found_socket = array_search($changed_socket, $clients);
@socket_getpeername($changed_socket, $ip);
unset($clients[$found_socket]);
}
}
}
socket_close($sock);
- Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.32, 7.2.29 - 7.2.33, 7.3.16 - 7.3.31, 7.4.3 - 7.4.32, 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- <?php$host = 'localhost';
$port = 7776;
$null = NULL;
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1);
socket_bind($socket, 0, $port);
socket_listen($socket);
$clients = array($socket);
while (true) {
$changed = $clients;
@socket_select($changed, $null, $null, 0, 10);
if (in_array($socket, $changed)) {
$socket_new = @socket_accept($socket);
$clients[] = $socket_new;
$header = socket_read($socket_new, 1024);
//perform_handshaking($header, $socket_new, $host, $port);
socket_getpeername($socket_new, $ip);
$found_socket = array_search($socket, $changed);
unset($changed[$found_socket]);
}
foreach ($changed as $changed_socket) {
while(@socket_recv($changed_socket, $buf, 1024, 0) >= 1)
{
//handle messages
}
$buf = @socket_read($changed_socket, 1024, PHP_NORMAL_READ);
//disconnect state
if ($buf === false) {
$found_socket = array_search($changed_socket, $clients);
@socket_getpeername($changed_socket, $ip);
unset($clients[$found_socket]);
}
}
}
socket_close($sock);
- Output for 8.0.13
- Parse error: syntax error, unexpected variable "$host" in /in/53fKZ on line 1
Process exited with code 255. - Output for 7.3.32 - 7.3.33, 7.4.33
- Parse error: syntax error, unexpected '$host' (T_VARIABLE) in /in/53fKZ on line 1
Process exited with code 255.
preferences:
152.46 ms | 401 KiB | 201 Q