I have been tasked with setting up a centralized computer that will need to make information requests to some 50 or 100 proxy machines. The central machine and each of the proxy machines will be running PHP. The basic idea is that the central machine will have a cron job running which will periodically need to request information from each of the proxies using a CURL request.
Given that it would be a total nightmare to update each of the proxy machines should I change my proxy code, I was hoping to set up the proxy code as a form that accepts POST data with a version number in it. The proxy machine would check that version number against a locally stored proxy number and if the supplied version number is a new version, the proxy machine will download a new code archive from a predetermined location and replace the old scripts before processing the rest of the POST data.
I'd like to avoid having to install any sort of DB so the proxies would need to store the version number in a text file - probably as a variable defined in the downloadable code. If anyone has suggestions about how best to do this, I would really appreciate it. I'm thinking something like this:
include 'code/version.php'; // this script just defines a var $code_version, containing the version number of the current code, it's part of the downloadable archive
if (version_compare($_POST['version'], $code_version) != 0) {
// download new version and unzip it
$filename = 'archive_' . $_POST['version'] . '.zip'
$foo = system('wget http://myserver.com/' . $filename, $output);
$foo = system($filename,$output);
// check the new version number
include 'code/version.php';
if (version_compare($_POST['version'], $code_version) != 0) {
// report error back to calling client
$error = array();
$error['msg'] = 'Unable to acquire proper code version';
die(serialize($error));
}
}
// if versions match, then execute code which will parse $_POST data
include 'code/process.php';
I suspect this will need a bit more validation. Can anyone recommend a better way to download? Any particular validation that should be done (such as the version number in POST data). Is there a better way to do this?