dimanche 13 avril 2014

Meilleur moyen de détecter la version installée dans une application web PHP - Stack Overflow


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



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!



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


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!


Related Posts:

0 commentaires:

Enregistrer un commentaire