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 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口