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?
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');
}