Reputation: 645
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,
My question is, is it possible to use single php thread to work with two synchronous ajax request?
Upvotes: 0
Views: 138
Reputation: 645
I finally ended up using websockets. And to implemet websockets in PHP i used Ratchet. I was able to get what i was trying to implement.
Upvotes: 0
Reputation: 643
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.
Upvotes: 2