Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to build a php mysql application that works offline

Tags:

php

mysql

offline

I have a web applications that stores data in a MySQL database on-line. It also retrieves data using PHP code, performs calculations on the server and sends the result back to the user.

Data it's quite simple: names, descriptions, prices, VAT, hourly charges that are read from the database and manipulated on the server side.

Often client work in environments where the internet connection is poor or not available. In this case I would like the client to be able to work offline: enter new names, descriptions, prices and use the last VAT to perform calculations. Then synchronise all data as soon as a connection is available.

Now the problem is that I do not know what is the best way or technologies for achieving this. Don't worry, I am not asking to write code for me. Can you just explain to me what is the correct way to build such a system?

Is there a simple way to use my online MySQL and PHP code locally?

Should I save the data I need in a local file, rebuild the calculation in JavaScript, perform them locally and then synchronise the data if database is available.

Should I use two MySQL database, one local and one online and do a synchronisation between the two when data is available? If yes which technology (language) shall I use to perform this operation?

If possible, I would like an answer from PHP coders that worked on a similar project in the past and can give me detailed information on framework structure and technology to use. please remember that I am new to this way of writing application and I would appreciate if you can spare few minutes and explain everything to me like if I am six year old or stupid (which I am!)

I really appreciate any help and suggestion.

Ciao,

Donato

like image 837
user1536396 Avatar asked Sep 04 '12 22:09

user1536396


People also ask

Can PHP be used offline?

In first type you can install and configure apache php and mysql one by one manually Or in second type use easy to install local server sotwares like xampp, wamp, easyPHP ect. By using any one method your pc will run as a server and you can easily test your php codes without any internet connectivity.

Can I use MySQL offline?

By default the application interacts with the MySQL on the server. If this server is not accessible (for what reason ever: server is offline or client has no internet connection) it should use the MySQL running on the client.

Is it compulsory to have a MySQL database when building websites with PHP?

No. PHP is a programming language. MySQL is a database.


2 Answers

I have worked with similar system for ships. Internet is expensive in the middle of the ocean so they have local web servers installed with database synchronization via e-mail.

We also have created simple .exe packages so people with no experience can install the system or update system...

like image 99
Juris Malinens Avatar answered Oct 31 '22 05:10

Juris Malinens


There are essentially 3 ways to go:

Version 1: "Old school": PHP-Gtk+ and bcompiler

  • first, if you not have done so already, you need to separate your business logic from your presentation layer (HTML, templating engines, ...) and database layer
  • then adapt your database layer, so that it can live with an alternative DB (local SQlite comes to mind) and perform synchronisation when online again
  • Finally use PHP-Gtk+ to create a new UI and pack all this with bcompiler

Version 2: "Standard": Take your server with you

  • Look at Server2Go, WampOnCD and friends to create a "double clickable webserver" (Start at Z-WAMP)
  • You still need to adapt your DB layer as in Version 1

Version 3: "Web 2.x": Move application from server to browser

  • Move your application logic from the server side (PHP) to the client side (JS)
  • Make your server part (PHP) only a data access or sync layer
  • Use the HTML5 offline features to replace your data access with local data if you are offline and to resync if online

Which one is best?

This depends on what you have and what you want. If most of your business logic is in PHP, then moving it into the browser might be prohibitingly expensive - be aware, that this also generates a whole new class of security nightmaares. I personally do not recommend porting this way, but I do recommend it for new apps, if the backing DB is not too big.

If you chose to keep your PHP business logic, then the desicion between 1 and 2 is often a quiestion of how much UI does your app have - if it's only a few CRUD forms, 1. might be a good idea - it is definitly the most portable (in the sense of taking it with you). If not, go with 2.

like image 30
Eugen Rieck Avatar answered Oct 31 '22 06:10

Eugen Rieck