I am new to websockets. Ive just completed my first multi-purpose socket server, which serves 3 types of messages on the same socket. This server is intended for use as follows:
chat messages
real time market data
user specific alerts
The first two functions work fine, and I'm completely happy, however, I experience a complete loss when it comes to identifying and linking peers in connection with specific accounts, so that I can serve pending alert notifications for specific users.
basically, I save the warnings in a database table as follows:
Table: uc_notifications
account(varchar50) | message(varchar255) | id(primary,AI) | seen(default 0)
I want to keep peers in a table like this:
uc_notification_peers
account(varchar50) | peer_id(unique,varchar100) | id(primary,AI)
, , , db , . script .
, , - websocket, onopen. websocket.
, , - , ip-. , , ip ( localhost ).
, , . - 2 , . ! , , , ( " №6" ). $clients , . , . , , .
function send_message_single_client($msg,$client)
{
@socket_write($client,$msg,strlen($msg));
return true;
}
, , 100 - .
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);
$query = $mysqli->query("SELECT * FROM (SELECT * FROM uc_chat_msg WHERE `hidden`='0' ORDER BY `id` DESC LIMIT 100) as last100 ORDER BY id");
while($row = $query->fetch_assoc()) {
$response_text = mask(json_encode(array('type'=>'usermsg', 'name'=>security($row["username"]), 'message'=>security($row["message"]), 'color'=>security($row["color"]))));
send_message_single_client($response_text, $socket_new);
}
$query->close();
unset($changed[$found_socket]);
}
, backburner, . , vps, / . php, facebook HHVM, , , , , .