0

We have a custom PHP/MySQL web application that gets updated and copied (using SFTP) to multiple servers regularly.

For some of those updates, database or filesystem changes are needed. Typically this requires manually running an update.php script that checks and updates everything.

I'd like to be able to have the application check whether there are new updates to decrease manual activity.

What would be the best way to do this?

Martijn
  • 3,696
  • 2
  • 38
  • 64

2 Answers2

1

You might be over thinking it?

Record the latest version in a file, record the current version in a script that you're uploading.

You can add as much complexity as you want to the version parsing.

Simplest possible example:

define('CURRENT_VERSION', 2);

$lastVersion = (int)file_get_contents('VERSION');

if (CURRENT_VERSION > $lastVersion) {
    if (update()) {
        file_put_contents('VERSION', CURRENT_VERSION);
    }
}

You could also detect the presence of an update by the fact that update.php exists. If it's there, run it and delete it. Obviously add your own error checking and fallback if update fails.

if (file_exists('update.php')) {
    require('update.php');
    unlink('update.php');
}
Leigh
  • 12,859
  • 3
  • 39
  • 60
  • I like the second idea; it's simple and has little performance overhead. Thnx. – Martijn Jun 26 '12 at 14:47
  • @Martijn: Make sure you do track the current/latest version inside update.php then, you wouldn't want to try and apply an update twice if it doesn't get deleted for some reason (permissions cock-up for example) – Leigh Jun 26 '12 at 16:15
0

you could try to store somewhere the version of the current application (example XML file) and the latest version of the application in a remote server into an XML file, then the only thing to do is run a cron job say once every 4 days or once a week to execute a php script which runs a comparison between current version and the XML file fetched from the remote server which has the latest version value, it should inform you via email, or a message at the application. additional information you can store in the XML files, are how critical this updates are, or information about the updates.

hope it helped!

Gntem
  • 6,949
  • 2
  • 35
  • 48