<?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>Piece of Unix Hints &#187; PHP</title>
	<atom:link href="http://hints.jeb.be/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://hints.jeb.be</link>
	<description>hints.jeb.be</description>
	<lastBuildDate>Fri, 04 Dec 2009 20:35:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Get HTTP arguments when using PHP as CGI</title>
		<link>http://hints.jeb.be/2008/12/17/get-http-arguments-when-using-php-as-cgi/</link>
		<comments>http://hints.jeb.be/2008/12/17/get-http-arguments-when-using-php-as-cgi/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 01:45:50 +0000</pubDate>
		<dc:creator>Jeb</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CGI]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://hints.jeb.be/?p=28</guid>
		<description><![CDATA[Normaly when you use PHP as CGI, $_GET and $_POST should work as usual. But in certain configuration, they may not be set. In this case this code is the base to get args foreach (split('&#38;',$QUERY_STRING) as $tmp) { $tmp2 = split('=',$tmp); $$tmp2[0]=$tmp2[1]; }]]></description>
			<content:encoded><![CDATA[<p>Normaly when you use PHP as CGI, $_GET and $_POST should work as usual.<br />
But in certain configuration, they may not be set. In this case this code is the base to get args</p>
<blockquote><p><code>foreach (split('&amp;',$QUERY_STRING) as $tmp) {<br />
$tmp2 = split('=',$tmp);<br />
$$tmp2[0]=$tmp2[1];<br />
}</code></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://hints.jeb.be/2008/12/17/get-http-arguments-when-using-php-as-cgi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remote Web Site Incremental Backup</title>
		<link>http://hints.jeb.be/2008/12/17/remote-web-site-incremental-backup/</link>
		<comments>http://hints.jeb.be/2008/12/17/remote-web-site-incremental-backup/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 01:41:32 +0000</pubDate>
		<dc:creator>Jeb</dc:creator>
				<category><![CDATA[Backup]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://hints.jeb.be/?p=22</guid>
		<description><![CDATA[Problem: You have a web site on a server but can&#8217;t connect to it with ssh but only FTP and you want to backup it daily but the website is huge, too huge to make a complete backup daily My solution is to put a php script on the webserver that list files with a [...]]]></description>
			<content:encoded><![CDATA[<p>Problem: You have a web site on a server but can&#8217;t connect to it with ssh but only FTP and you want to backup it daily but the website is huge, too huge to make a complete backup daily</p>
<p>My solution is to put a php script on the webserver that list files with a modification date in the last X seconds.<br />
Then within the following shell script I get the result of the php page then I retreive  listed file using FTP.</p>
<p>This is, I think, the most generic solution. I see an other one:</p>
<ul>
<li>It would be to create a tar archive in the php script, then download the .tar directly. This as 2 problems: It&#8217;s less secure unless you can apply an htaccess file on the .tar file to put an auth, you may not be allowed to execute binary on the remote server to do the tar.</li>
<li>You may also use <a class="ext-link" href="http://en.wikipedia.org/wiki/FTPFS" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/FTPFS?referer=');"><span class="icon">FTPFS</span></a>, it&#8217;s nice, but require that the host making the backup can use ftpfs <img src='http://hints.jeb.be/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
</ul>
<p>This is the source of my SH script</p>
<div class="code">
<pre>#! /bin/sh

BK_YEAR="`date +%Y`"
BK_MONTH="`date +%b`"
BK_DAY="`date +%d`"

for file in `lynx -auth=login:password -source http://www.domain.com/admtool/last-modified.php`
do ADL="`echo $file | sed "s|/path/to/www.domain.com/root/document/or/the/ftp/chroot/path/||"`"
mkdir -p "/some/path/backup/domain.com/$BK_YEAR/$BK_MONTH/$BK_DAY/web-page/`dirname $ADL`"
wget -q --output-document="/some/path/backup/domain.com/$BK_YEAR/$BK_MONTH/$BK_DAY/web-page/$ADL" -r "ftp://login:pass@ftp.domain.com/$ADL"
done

tar -czf "/some/path/backup/domain.com/$BK_YEAR/$BK_MONTH/$BK_DAY/web-page.tgz" "/some/path/backup/domain.com/$BK_YEAR/$BK_MONTH/$BK_DAY/web-page"
rm -r "/some/path/wd1a/backup/domain.com/$BK_YEAR/$BK_MONTH/$BK_DAY/web-page"</pre>
</div>
<p>This is the source of my PHP script</p>
<div class="code">
<pre><span class="code-lang">&lt;?php 

$path </span><span class="code-keyword">= </span><span class="code-string">'.'</span><span class="code-keyword">;</span>
<span class="code-lang">$time </span><span class="code-keyword">= </span><span class="code-lang">86400</span><span class="code-keyword">;      </span><span class="code-comment">// will print all file modified in the last 86400 seconds</span>

<span class="code-lang">$curtime </span><span class="code-keyword">= </span><span class="code-lang">time</span><span class="code-keyword">();</span>

<span class="code-lang">GetFileList</span><span class="code-keyword">(</span><span class="code-lang">$path</span><span class="code-keyword">);

function </span><span class="code-lang">GetFileList</span><span class="code-keyword">(</span><span class="code-lang">$path</span><span class="code-keyword">) {</span>
<span class="code-lang">$curtime </span><span class="code-keyword">= </span><span class="code-lang">time</span><span class="code-keyword">();
        </span><span class="code-lang">$handle</span><span class="code-keyword">=</span><span class="code-lang">opendir</span><span class="code-keyword">(</span><span class="code-lang">$path</span><span class="code-keyword">);
                while(</span><span class="code-lang">$file </span><span class="code-keyword">= </span><span class="code-lang">readdir</span><span class="code-keyword">(</span><span class="code-lang">$handle</span><span class="code-keyword">)) {
                        if (</span><span class="code-lang">$file</span><span class="code-keyword">==</span><span class="code-string">'.' </span><span class="code-keyword">|| </span><span class="code-lang">$file</span><span class="code-keyword">==</span><span class="code-string">'..'</span><span class="code-keyword">) continue;
                        if (</span><span class="code-lang">is_dir</span><span class="code-keyword">(</span><span class="code-lang">$path </span><span class="code-keyword">. </span><span class="code-string">'/' </span><span class="code-keyword">. </span><span class="code-lang">$file</span><span class="code-keyword">)) {
                                </span><span class="code-lang">GetFileList</span><span class="code-keyword">(</span><span class="code-lang">$path </span><span class="code-keyword">. </span><span class="code-string">'/' </span><span class="code-keyword">. </span><span class="code-lang">$file</span><span class="code-keyword">);
                        }
                        else {
                                if ((</span><span class="code-lang">$curtime </span><span class="code-keyword">- </span><span class="code-lang">filemtime</span><span class="code-keyword">(</span><span class="code-lang">$path </span><span class="code-keyword">. </span><span class="code-string">'/' </span><span class="code-keyword">. </span><span class="code-lang">$file</span><span class="code-keyword">)) &lt; </span><span class="code-lang">86400</span><span class="code-keyword">) {
                                        echo </span><span class="code-lang">$path </span><span class="code-keyword">. </span><span class="code-string">'/' </span><span class="code-keyword">. </span><span class="code-lang">$file </span><span class="code-keyword">. </span><span class="code-string">"n"</span><span class="code-keyword">;
                                }
                        }
                }
        </span><span class="code-lang">closedir</span><span class="code-keyword">(</span><span class="code-lang">$handle</span><span class="code-keyword">);
}</span>

<span class="code-lang">?&gt;</span></pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://hints.jeb.be/2008/12/17/remote-web-site-incremental-backup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
