du1462 2017-05-01 20:54
浏览 641

Websocket和用户标识(PHP)

Let's say i want to identify each user that initiate a connection to a php websocket server (Ratchet).

Each user have an unique token in my database (not enough secure i know, but let's keep this example simple).

I have to send this token when opening the connection to the WS server and check in my database if it match any user and if yes allowing to continue and storing the connection id of the WS to be able to link the user to the ws connection.

Then connected user id 1 want's to send a message to connected user id 2

Do i have to search in the database the connection id of user 2 to be able to send the message ? or does there is an alternative, like a global array which stay in the memory or something and where the WS server can access it all time ? this would be less heavy than requesting the database if i just could store a link between "user Id" and "ws connection Id" directly in the memory or something

  • 写回答

1条回答 默认 最新

  • dongyu4863 2017-05-01 21:02
    关注

    this would be less heavy than requesting the database if i just could store a link between "user Id" and "ws connection Id" directly in the memory or something

    If by "storing in memory", you mean over the same session, then PHP SESSIONS are what you need. That way, every information you want to access within that same session is literally "stored in memory".

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型