dsdv76767671 2015-10-29 09:08
浏览 77

单个PHP线程响应两个异步ajax请求

I am implementing a synchronization process between two devices. Web and mobile. I have planned an algorithm but not sure about the possibility of its implementation. My algorithm is,

  1. Mobile will generate a ajax request to PHP script to sync its data onto database.
  2. PHP scripts starts a transaction, then insert data into to database that mobile sent and collects data that it has to send to mobile and send resposce but do not commit.
  3. Mobile receives response, starts a transaction, and send another ajax request as acknowledgement to php script and commit at mobile side.
  4. PHP script receives acknowledgement ajax request and commit its data as well that i developed in setp 2.

My question is, is it possible to use single php thread to work with two synchronous ajax request?

  • 写回答

2条回答 默认 最新

  • doucan9079 2015-10-29 10:07
    关注

    I will leave the php concepts to experts.

    We had a similar scenario, where we would send the data to server and insert it with a flag value (e.g., incomplete), then we will acknowledge back to device saying that xyz rows were inserted. It will also contain an unique identifier per device so that we can keep track of which device sent what data, we will also maintain the details of unique identifier per device, unique transaction id (uuid) and timestamp in a separate table (transaction_status). The acknowledgement will be updated in clients, this will basically remove the transactions from the sync queue maintained on the client.

    When the next set of records from the same client reaches server, the server will query for the matching entries in the transaction_status table. if the entries are already available, it means that the acknowledgement did not reach the client and server will respond with necessary data in such case.

    If the next set of records did not contain the entries which were sent during previous sync then those considered as successful sync and the incomplete flag will be update.

    I understand that this might be vague, but i will try to create a diagram in my free time to clearly depict this scenario.

    Please leave a comment if you need more clarification.

    Anyone having a better approach, please feel free to share.

    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值