<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Juozas devBlog &#187; upload</title>
	<atom:link href="http://dev.juokaz.com/tag/upload/feed" rel="self" type="application/rss+xml" />
	<link>http://dev.juokaz.com</link>
	<description>Random ideas, scripts and facts</description>
	<lastBuildDate>Mon, 22 Mar 2010 10:48:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using Phing to sync files with shared hosting</title>
		<link>http://dev.juokaz.com/php/using-phing-to-synchronize-files</link>
		<comments>http://dev.juokaz.com/php/using-phing-to-synchronize-files#comments</comments>
		<pubDate>Fri, 27 Feb 2009 19:14:20 +0000</pubDate>
		<dc:creator>Juozas</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[ant]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[blogs]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[code in the hole]]></category>
		<category><![CDATA[ftp]]></category>
		<category><![CDATA[head]]></category>
		<category><![CDATA[id]]></category>
		<category><![CDATA[phing]]></category>
		<category><![CDATA[php::impact]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[repository]]></category>
		<category><![CDATA[revision]]></category>
		<category><![CDATA[subversion]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[upload]]></category>

		<guid isPermaLink="false">http://dev.juokaz.com/?p=284</guid>
		<description><![CDATA[Phing is a project build system. It&#8217;s wonderful tool to automate every-days task by writing build scenario &#8211; 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&#8217;t do a lot of it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://phing.info/trac/"><img class="size-full wp-image-292" style="float: right;" title="Phing" src="http://dev.juokaz.com/wp-content/uploads/2009/02/logo.gif" alt="Phing" width="197" height="58" />Phing</a> is a project build system. It&#8217;s wonderful tool to automate every-days task by writing build scenario &#8211; 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&#8217;t do a lot of it&#8217;s functionality without direct access to server (over shh for example).</p>
<p><a href="http://phpimpact.wordpress.com/">PHP::Impact blog</a> has very nice <a href="http://phpimpact.wordpress.com/2008/07/21/filesynctask-using-phing-to-synchronize-files-and-directories/">article</a> about remote files synchronization. Given FileSyncTask library uses <a href="http://samba.anu.edu.au/rsync/"><em>rsync</em></a>, 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.</p>
<p><a href="http://codeinthehole.com">Code in the hole</a> some months ago posted <a href="http://codeinthehole.com/archives/13-Deploying-to-a-shared-hosting-environment-using-Phing.html">solution</a> 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:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;project</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;project&quot;</span> <span style="color: #000066;">basedir</span>=<span style="color: #ff0000;">&quot;.&quot;</span> <span style="color: #000066;">default</span>=<span style="color: #ff0000;">&quot;build&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;build.properties&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${sync.projectdir}/&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;files.main&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;**/*&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #808080; font-style: italic;">&lt;!-- netbeans project folder --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;exclude</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;nbproject/**&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fileset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;build&quot;</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;svnexport,deploy-application-files&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;deploy-application-files&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo</span> <span style="color: #000066;">msg</span>=<span style="color: #ff0000;">&quot;Deploying application files&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;phingcall</span> <span style="color: #000066;">target</span>=<span style="color: #ff0000;">&quot;deploy&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;deploy.fileset.refid&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;files.main&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/phingcall<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;deploy&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ftpdeploy</span></span>
<span style="color: #009900;">	    <span style="color: #000066;">host</span>=<span style="color: #ff0000;">&quot;${ftp.host}&quot;</span> <span style="color: #000066;">port</span>=<span style="color: #ff0000;">&quot;${ftp.port}&quot;</span></span>
<span style="color: #009900;">	    <span style="color: #000066;">username</span>=<span style="color: #ff0000;">&quot;${ftp.username}&quot;</span> <span style="color: #000066;">password</span>=<span style="color: #ff0000;">&quot;${ftp.password}&quot;</span></span>
<span style="color: #009900;">	    <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${ftp.dir}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">refid</span>=<span style="color: #ff0000;">&quot;${deploy.fileset.refid}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ftpdeploy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;svnexport&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;delete</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${sync.projectdir}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;svnexport</span></span>
<span style="color: #009900;">	    <span style="color: #000066;">username</span>=<span style="color: #ff0000;">&quot;${svn.username}&quot;</span> <span style="color: #000066;">password</span>=<span style="color: #ff0000;">&quot;${svn.password}&quot;</span></span>
<span style="color: #009900;">	    <span style="color: #000066;">nocache</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">force</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">	    <span style="color: #000066;">repositoryurl</span>=<span style="color: #ff0000;">&quot;${svn.repo}&quot;</span> <span style="color: #000066;">todir</span>=<span style="color: #ff0000;">&quot;${sync.projectdir}&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/project<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Project was successfully uploaded, but it took more than half an hour (I have university Internet which is very fast). Problem is, it doesn&#8217;t check for files changes &#8211; it just uploads every single file in <em>fileset</em>. I don&#8217;t blame anyone, FTP is not made for syncing files and uploading huge amount of tiny files is very slow. We need other solution.</p>
<p>I have come up with another idea, which works by:</p>
<ol>
<li>Get <em>last-revision-id</em> from production server</li>
<li>Download modified files (difference from last-revision-id to HEAD) from SVN repository</li>
<li>Upload modified files</li>
<li>Change<em> last-revision-id</em> to current ID</li>
</ol>
<p>It works in theory and can be really simply implemented with Phing, but it&#8217;s still not very good solution. There is too much trust for one file (<em>last-revision-id</em>). Unless you can make sure that nobody will touch any files inside server without using Phing build script, things can easily brake. That&#8217;s why I haven&#8217;t tried it.</p>
<p>Have you used anything like this? Currently I&#8217;m thinking about moving to different server, because these limits (no <a href="http://en.wikipedia.org/wiki/Secure_Shell">ssh</a>) 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.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.juokaz.com/php/using-phing-to-synchronize-files/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
