Phing is a project build system. It’s wonderful tool to automate every-days task by writing build scenario – Phing can do everything what can be done with PHP or Linux console applications. Today I was trying to use it in shared hosting server, but as you will see, Phing can’t do a lot of it’s functionality without direct access to server (over shh for example).
PHP::Impact blog has very nice article about remote files synchronization. Given FileSyncTask library uses rsync, console utility, which is de-facto standard for syncing files. Everything sounds great, but things get worse, when you try to sync files in shared hosting environment, where only FTP is available.
Code in the hole some months ago posted solution which uses Net_FTP (FTP functionality wrapper) package to upload files to server. I decided to try given solution, so I modified it to download source code from SVN first and then upload them. My tests code:
<?xml version="1.0" ?> <project name="project" basedir="." default="build"> <property file="build.properties" /> <fileset dir="${sync.projectdir}/" id="files.main"> <include name="**/*" /> <!-- netbeans project folder --> <exclude name="nbproject/**" /> </fileset> <target name="build" depends="svnexport,deploy-application-files" /> <target name="deploy-application-files"> <echo msg="Deploying application files" /> <phingcall target="deploy"> <property name="deploy.fileset.refid" value="files.main"/> </phingcall> </target> <target name="deploy"> <ftpdeploy host="${ftp.host}" port="${ftp.port}" username="${ftp.username}" password="${ftp.password}" dir="${ftp.dir}"> <fileset refid="${deploy.fileset.refid}" /> </ftpdeploy> </target> <target name="svnexport"> <delete dir="${sync.projectdir}" /> <svnexport username="${svn.username}" password="${svn.password}" nocache="true" force="true" repositoryurl="${svn.repo}" todir="${sync.projectdir}" /> </target> </project>
Project was successfully uploaded, but it took more than half an hour (I have university Internet which is very fast). Problem is, it doesn’t check for files changes – it just uploads every single file in fileset. I don’t blame anyone, FTP is not made for syncing files and uploading huge amount of tiny files is very slow. We need other solution.
I have come up with another idea, which works by:
- Get last-revision-id from production server
- Download modified files (difference from last-revision-id to HEAD) from SVN repository
- Upload modified files
- Change last-revision-id to current ID
It works in theory and can be really simply implemented with Phing, but it’s still not very good solution. There is too much trust for one file (last-revision-id). Unless you can make sure that nobody will touch any files inside server without using Phing build script, things can easily brake. That’s why I haven’t tried it.
Have you used anything like this? Currently I’m thinking about moving to different server, because these limits (no ssh) for bigger projects creates massive headaches. I have came up with some hacks, as written above, but they are too sensitive and just mimics actual synchronization.







