Page 1 of 2

Auto-updating PHP software

Posted: Sun Jan 29, 2006 7:56 pm
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.

Posted: Sun Jan 29, 2006 7:59 pm
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. :)

Posted: Sun Jan 29, 2006 8:04 pm
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.

Posted: Sun Jan 29, 2006 8:05 pm
by Ambush Commander
But vBulleting is not free. Alas, alas.

Posted: Sun Jan 29, 2006 8:07 pm
by Jenk
True, but I'll take a look in the morning to see how it does this ;)

Posted: Sun Jan 29, 2006 8:10 pm
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... ;)

Posted: Sun Jan 29, 2006 8:26 pm
by feyd
torrent it? :lol: (kinda serious though)

Posted: Sun Jan 29, 2006 8:30 pm
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.

Posted: Sun Jan 29, 2006 8:32 pm
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?"

Posted: Sun Jan 29, 2006 8:38 pm
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.

Posted: Sun Jan 29, 2006 8:44 pm
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.

Posted: Sun Jan 29, 2006 8:45 pm
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

Posted: Mon Jan 30, 2006 12:33 am
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

Posted: Mon Jan 30, 2006 12:46 am
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)

Posted: Mon Jan 30, 2006 2:51 am
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.