anand_aks's avatar

Sync local mySql DB with Cloud mySql DB at a particular time intervel

I have a laravel application for a restaurant that the client wants the offline feature. What we can do is host the application locally using phpdesktop and if the internet goes out the application should work and save the data locally. When the internet comes back sync the new data to the live server.

Is any particular way I can do this? I have checked the SQL replication already. Any better solution to this problem?

0 likes
9 replies
Ben Taylor's avatar

You could build a pwa and store offline data in indexDB on the client and then sync it when they come back online

anand_aks's avatar

@Ben Taylor Okay. But the question is how do I sync it when it comes online? Using which tool or application, like rsync, SQL replication

Ben Taylor's avatar

@anand_aks just do it yourself. Whatever record in indexeddb that doesn't have an id has been created on the client while offline and needs to be saved to server DB.

martinbean's avatar

@anand_aks Might be worth Googling when someone suggests something.

A PWA is a Progressive Web App. It uses a service worker under the hood. The user interacts with the web app, even if they’re offline. You can store things in a local database, i.e. IndexedDB. When you detect you have a network connection again, all the records in the local database can then be sent to the server using AJAX requests.

jlrdw's avatar

Also another option instead of worrying about syncing, simply have two databases. That way you don't run into having to deal with duplicates. Bear in mind if the internet is down, a customer can't order anyway, all has to be done locally in the restaurant. But just a suggestion.

At the time for reports, I.e., simply use data from both databases combined for income and expense reports, etc.

But there are many ways to do this.

anand_aks's avatar

@jlrdw Keeping Multiple DB is not a good option for me. We have many branches and the network connection is not good. So we have to put the DB locally for each branch and these data need to sync with the single cloud DB so that the management can view all the different reports daily.

jlrdw's avatar

@anand_aks

We have many branches

In such a case do not use an online database for customers.

  • have a local db at each place, same code base
  • sync all to the online db daily
  • only use online db for admins, bookkeepers for accounting

Each place will have a unique id, i.e., for that restaurant like:

  • R1
  • R2
  • R3
  • etc

Just suggestions

anand_aks's avatar

@jlrdw Thanks for the reply. But my question is How do I sync the local Db with Cloud DB? Using what method or tool? How do I do the sync?

jlrdw's avatar

@anand_aks

How do I do the sync?

You don't sync, you then upload (insert) the data to the master (online) database.

If you want something more complex, it will require time and much more cost. I only tried to suggest a simpler solution.

Otherwise have the internet providers where you live not go offline, to have 99 percent uptime..

Edit:

Here is a post with links that might help:

https://stackoverflow.com/questions/46532965/creating-a-web-app-that-can-work-offline-store-data-and-then-sync-it-to-remote

Please or to participate in this conversation.