Auto-updating PHP software
Moderator: General Moderators
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
Auto-updating PHP software
Have you ever seen a third-party PHP application that has the ability to phone into the server and automatically download/install updates? It would make my life a lot easier (instead of having to track three+ seperate packages and do the maintenance work we all hate doing) and would also be damn cool.
vBulletin has this feature. Not entirely sure what it checks against, but in the past we have had projects that use date modified fields, or plain old version number comparisons.
Sometimes a text file with the latest date or version in makes a good choice.
Sometimes a text file with the latest date or version in makes a good choice.
Last edited by Jenk on Sun Jan 29, 2006 8:07 pm, edited 1 time in total.
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
Rewriting the files wouldn't be very difficult to do: the problem is distributing the download so that the admin doesn't have to sit down, click update, and then wait for the script to finish updating (or you could do that).
You could, I suppose, transfer it in shards, and randomly download 256KB bits from the main website as users view the site. If it's a Unix system, you could try forking the process, although I can see where that would run into problems. You could, of course, inadvertantly DOS your website if you're not careful...
You could, I suppose, transfer it in shards, and randomly download 256KB bits from the main website as users view the site. If it's a Unix system, you could try forking the process, although I can see where that would run into problems. You could, of course, inadvertantly DOS your website if you're not careful...
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
File permissions seems to be the biggest problem. If the user initally installed the app/files manually then PHP (in many cases) will not not have write permissions on those files.
FTP seems to be a reasonable choice for getting round that issue but then you are into the realms of protecting the users FTP password.
Currently the best method I have found is using cURL to transfer the files in to a 'temp' directory on the clients server, then FTP (internally via the loopback) the files from the temp directory to the actual install directory.
Server to server transfers are normally pretty quick as are file writes, I'd say for small to medium sized applications you wouldn't be sitting around too long waiting for the update.
Other issues, you need a way/mechanism to lock your app during the update so users don't get loads of errors thrown up at them (a simple lock file seems to do the trick). There is no margin for error.
FTP seems to be a reasonable choice for getting round that issue but then you are into the realms of protecting the users FTP password.
Currently the best method I have found is using cURL to transfer the files in to a 'temp' directory on the clients server, then FTP (internally via the loopback) the files from the temp directory to the actual install directory.
Server to server transfers are normally pretty quick as are file writes, I'd say for small to medium sized applications you wouldn't be sitting around too long waiting for the update.
Other issues, you need a way/mechanism to lock your app during the update so users don't get loads of errors thrown up at them (a simple lock file seems to do the trick). There is no margin for error.
Well I know you said *most* but it wouldn't be hard to have an executable script that gets chmodded +x on the install of the application, and your update script just pushes data to be written through the PHP shell script, the shell script could verify it's coming from your update script and the shell script would not be run as apache or as the web-server. Keep in mind you'd probably want this feature to be opt-in, not all your users would not be contempt with having their scripts updated automatically like that.
Edit for redmonkey.
You could install the new files into a separate directory and when the new directory is complete rename the directories, this also brings up a new idea where the admin logs in and sees "new updates are ready to be installed, please click here" or whatever
Edit for redmonkey.
You could install the new files into a separate directory and when the new directory is complete rename the directories, this also brings up a new idea where the admin logs in and sees "new updates are ready to be installed, please click here" or whatever
By looking at his server you mean the server that is hosting the updates? That is the only feasible way to do it and was kind of implied, and by intervals what do you mean? I would say bi-daily checks for updates are more than enough.. you don't want everyone hitting you at the same time anyways. As for re-implementing the torrent protocool there is a lot more to it then what you would think feyd. You have to be able to check the integrity of blocks of files, you would need a server that would act as a tracker, etc... I'd rather just pay for the bandwidth unless it's something really really insane. Either that or just offer a real bittorrent download and let the users install it themselves. Another option would be just downloading pages that have changed (no need to re-download code that has not changed between updates)
The biggest headache I've found with auto-updating things is dependencies .. what to do if the user misses an update, or five updates .. if you only include files, or blocks, that have changed since the last update then the user's application will break if they install updates out of order. The way I got around it was to have a 'versions' database (well, file actually) that the update script checks and refuses to install anything unless the version number in the database matchs the 'old' version number in the update. It was an immense amount of hassle to get working properly though so I gave up eventually. Mind you, that was about 4 years ago when I was a lot less skilled at PHP. It was probably my lack of ability that made it hard rather than the code itself.