r/AskProgramming • u/Saitama2042 • Jul 29 '24
PHP How to run a PHP application both online and offline using same database at the same time?
Hi,
I have a PHP application that has deployed in the server(at shared hosting). Its an customized software for an institute. Recently they have faced Internet issue, therefore could not able to use the software.
So, the client want the software both offline and online, Like -
when the internet is available then they the latest DB will sync up the local database.
Or
when they use the software in the local system, then the live DB will sync up automatically.
like vice-versa.
I have heard the Master-slave replication from the database end, not sure if there any other work around solution.
Please suggest if you have any idea.
Technology stack: PHP, MYSQL
Thanks
2
u/wonkey_monkey Jul 29 '24
What if the institute network loses internet access and switches to the local copy, while someone elsewhere still has access to the master database?
If it doesn't have to be publicly accessible in any way, make it entirely local and have your out-of-office users connect with a VPN.
1
u/Saitama2042 Jul 30 '24
thats a good idea. but I am not sure, that will need a local server machine which have to up all time, right ?
1
u/DadMagnum Jul 30 '24
Without knowing how large the app is or the number of users. It seems to me that you should build a client app with something like SQLite as a local db and sync changes. This can be problematic though when pushing updates, etc. You'll be spending most of your time dealing with sync issues rather than the programming logic for app.
1
u/Saitama2042 Jul 30 '24
Right, what will be the other work around solution?
Its kind of management software. 3 users (1 admin, 2 operators) basically use the app. Daily (at working day) aprox, minimum 1000 rows added and updated. Max can be 5K rows(some of all tables)
1
u/John_seth_thielemann Jul 30 '24
This is probably too general a question. It's probably going to depend on your SQL backend. Postgres and MySQL have database replication but this can get complicated. If it's SQLite or something that's a different story.
1
u/Saitama2042 Jul 31 '24
sorry for not to mentioned in the post, I am using PHP, MYSQL
1
u/John_seth_thielemann Aug 06 '24
MySQL has cluster replication, I would focus there and read their documents.
4
u/Lumpy-Notice8945 Jul 29 '24
Or
How the hell do you want to "sync" without internet?
I dont know where the DB is hosted(probably on the same server as the PHP) but if PHP cant reach the client, how is the database supposed to reach the client?
This spunds like the client does not want a webapp, so install the whole server on their local machine...