Auto-updating PHP software

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Auto-updating PHP software

Post by Ambush Commander »

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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

although I haven't seen it, I have been working on ways of doing it for the forums/cms/whatever I'm getting set to build. :)
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

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.
Last edited by Jenk on Sun Jan 29, 2006 8:07 pm, edited 1 time in total.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

But vBulleting is not free. Alas, alas.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

True, but I'll take a look in the morning to see how it does this ;)
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

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... ;)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

torrent it? :lol: (kinda serious though)
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Depends on how difficult the spec is. And without spawning a background process, we would have to figure out to adapt the protocol to short bursts of transfers. I think.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

wouldn't be all that far fetched.. "here's the indexes of blocks I have, give me something I don't have" which would switch at some depreciating value point to "do you have this index?"
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

Keep in mind that in most situations, to update the files, the files have to be writable by the webserver. Not the most secure choice.
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

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.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

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
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

Post by AGISB »

How about creating a cron script that looks in certain intervals at your server and see if there is an update? If there is the script fetches the updated scripts and installs them
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

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)
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

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.
Post Reply