<?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>~ overflow ~ &#187; z3n</title>
	<atom:link href="http://www.overflow.biz/blog/lang/en-us/author/z3n/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.overflow.biz/blog</link>
	<description>Coding and Internet Randomness</description>
	<lastBuildDate>Sun, 08 Jan 2012 23:34:17 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en-us</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Server overload warning</title>
		<link>http://www.overflow.biz/blog/lang/en-us/2011/12/27/server-overload-warning?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=server-overload-warning</link>
		<comments>http://www.overflow.biz/blog/lang/en-us/2011/12/27/server-overload-warning#comments</comments>
		<pubDate>Tue, 27 Dec 2011 19:08:06 +0000</pubDate>
		<dc:creator>z3n</dc:creator>
				<category><![CDATA[Linux Happyness]]></category>
		<category><![CDATA[Tips & Hints]]></category>
		<category><![CDATA[alert]]></category>
		<category><![CDATA[beep]]></category>
		<category><![CDATA[overload]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://www.overflow.biz/blog/?p=535</guid>
		<description><![CDATA[Problem:
So i have this shitty server that keeps overloading, although i have all sort of monitors around, many screens, etc I really can&#8217;t keep looking at the graphs all day long, but yet i&#8217;m almost of the time on the computer.
So why not have a sound trigger when server load go over 10?
Solution:
This php script [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong></p>
<p>So i have this shitty server that keeps overloading, although i have all sort of monitors around, many screens, etc I really can&#8217;t keep looking at the graphs all day long, but yet i&#8217;m almost of the time on the computer.</p>
<p>So why not have a sound trigger when server load go over 10?</p>
<p><strong>Solution:</strong></p>
<p>This php script solves it:</p>
<pre class="brush: php;">
// (c) z3n - R1V1@111227 - www.overflow.biz - rodrigo.orph@gmail.com

while (true) {
	$output = explode(&#34; &#34;, trim(substr(strstr(exec(&#34;uptime&#34;), &#34;load average:&#34;), 13)));
        if (substr($output[0], 0, -1) &#62; 10)
		@ passthru(&#34;echo -e -n \\\\a&#34;);

	echo &#34;\r[&#34; . date(&#34;Y-m-d H:i:s&#34;) . &#34;] &#34; . implode(&#34; &#34;, $output);
	sleep(5);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.overflow.biz/blog/lang/en-us/2011/12/27/server-overload-warning/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Facebook auto poker</title>
		<link>http://www.overflow.biz/blog/lang/en-us/2011/12/27/facebook-auto-poker?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=facebook-auto-poker</link>
		<comments>http://www.overflow.biz/blog/lang/en-us/2011/12/27/facebook-auto-poker#comments</comments>
		<pubDate>Tue, 27 Dec 2011 15:22:51 +0000</pubDate>
		<dc:creator>z3n</dc:creator>
				<category><![CDATA[Linux Happyness]]></category>
		<category><![CDATA[Tips & Hints]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[poke]]></category>

		<guid isPermaLink="false">http://www.overflow.biz/blog/?p=532</guid>
		<description><![CDATA[I wrote this macro with XTE intended to run on linux on a VNC screen, nothing a regular geek wouldn&#8217;t understand.
Never loose a poke war ever again:

while [ 1 ] ; do xte 'mousemove 20 350' 'mouseclick 1';sleep 5;xte 'mousemove 300 235' 'mouseclick 1';sleep 30;done;

]]></description>
			<content:encoded><![CDATA[<p>I wrote this macro with XTE intended to run on linux on a VNC screen, nothing a regular geek wouldn&#8217;t understand.</p>
<p>Never loose a poke war ever again:</p>
<pre class="brush: bash;">
while [ 1 ] ; do xte 'mousemove 20 350' 'mouseclick 1';sleep 5;xte 'mousemove 300 235' 'mouseclick 1';sleep 30;done;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.overflow.biz/blog/lang/en-us/2011/12/27/facebook-auto-poker/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FTP not working?</title>
		<link>http://www.overflow.biz/blog/lang/en-us/2011/05/24/ftp-not-working?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=ftp-not-working</link>
		<comments>http://www.overflow.biz/blog/lang/en-us/2011/05/24/ftp-not-working#comments</comments>
		<pubDate>Tue, 24 May 2011 20:40:14 +0000</pubDate>
		<dc:creator>z3n</dc:creator>
				<category><![CDATA[Linux Happyness]]></category>
		<category><![CDATA[block]]></category>
		<category><![CDATA[ftp]]></category>
		<category><![CDATA[ftpd]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[selinux]]></category>

		<guid isPermaLink="false">http://www.overflow.biz/blog/?p=530</guid>
		<description><![CDATA[Problem:
FTPd is working however when you try to login you get access denied on user&#8217;s home folder, no matter what accesses and group/user combination.
Solution:
Check /var/log/audit/autit.log and /var/log/messages
This usually is a SELinux block, fix it using:
 setsebool -P ftp_home_dir=1
]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong></p>
<p>FTPd is working however when you try to login you get access denied on user&#8217;s home folder, no matter what accesses and group/user combination.</p>
<p><strong>Solution:</strong><br />
Check /var/log/audit/autit.log and /var/log/messages<br />
This usually is a SELinux block, fix it using:</p>
<pre class="brush: bash;"> setsebool -P ftp_home_dir=1</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.overflow.biz/blog/lang/en-us/2011/05/24/ftp-not-working/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL InnoDB ibdata size</title>
		<link>http://www.overflow.biz/blog/lang/en-us/2011/04/03/mysql-innodb-ibdata-size?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=mysql-innodb-ibdata-size</link>
		<comments>http://www.overflow.biz/blog/lang/en-us/2011/04/03/mysql-innodb-ibdata-size#comments</comments>
		<pubDate>Sun, 03 Apr 2011 12:39:53 +0000</pubDate>
		<dc:creator>z3n</dc:creator>
				<category><![CDATA[Tips & Hints]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[ibdata]]></category>
		<category><![CDATA[innodb size]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[recreation]]></category>

		<guid isPermaLink="false">http://www.overflow.biz/blog/?p=525</guid>
		<description><![CDATA[Problem:
MySQL InnoDB ibdata file size never shrinks no matter if you deleted a big database / table or whatever.
Solution:
There is no easy solution for this, according to mysql this is supposed to be a bug, however they never fixed it since, apparently, there&#8217;s not many people around deleting big tables / databases.
Looking around, someone suggested [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong></p>
<p>MySQL InnoDB ibdata file size never shrinks no matter if you deleted a big database / table or whatever.</p>
<p><strong>Solution:</strong></p>
<p>There is no easy solution for this, according to mysql this is supposed to be a bug, however they never fixed it since, apparently, there&#8217;s not many people around deleting big tables / databases.</p>
<p>Looking around, someone suggested that recreating the whole dataset would help fixing the issue, since we won&#8217;t be having trash on the innodb ibdata file.</p>
<p>Recreating the whole dataset is a extremely time consuming task, you would need to do a dump of every database, completly delete mysql data folder, create a new one with defaults, and inject the dump file. Just for example, on my dev machine i run about 100 different databases the total size is around 8GB, innodb was 20GB, wasting a lot of space on my precious SSD, so dumping everything, doing backups and injecting the whole data took over 8 hours, which is something nobody can take on a production server.</p>
<p>After some more research I&#8217;ve found about a specific configuration switch:</p>
<pre class="brush: bash;">
innodb_file_per_table
</pre>
<p>This is what you should have on your my.cnf or my.ini into the innodb branch. Instead of creating one big innodb ibdata for every single innodb table across all databases, this switch will create a `.ibd` file for each of the the innodb tables. Those files will be stored inside the database folder, so if you eventually have a greatly sized table you just need to drop it and recreate the single table to avoid gigantic innodb .ibd files instead of doing a full database recreation.</p>
<p>If you don&#8217;t have time to recreate everything you can just add `innodb_file_per_table`  into the config, so new tables will be created using the new scheme.</p>
<p>The only con i can think about this switch is because you will have one extra file that will have to be seeked and will incrase the overhead when doing table joins and so on, although the disk overhead should be minimal, if you have thousands of tables into the same db it might make some difference, if you relay on speed you should do some benchmarks to make sure.</p>
<p><strong>Bug Tracking:</strong></p>
<p><a href="http://bugs.mysql.com/bug.php?id=1341" target="_blank">bugs.mysql.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.overflow.biz/blog/lang/en-us/2011/04/03/mysql-innodb-ibdata-size/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Finding big files on linux</title>
		<link>http://www.overflow.biz/blog/lang/en-us/2011/04/02/finding-big-files-on-linux?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=finding-big-files-on-linux</link>
		<comments>http://www.overflow.biz/blog/lang/en-us/2011/04/02/finding-big-files-on-linux#comments</comments>
		<pubDate>Sat, 02 Apr 2011 21:44:05 +0000</pubDate>
		<dc:creator>z3n</dc:creator>
				<category><![CDATA[Linux Happyness]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.overflow.biz/blog/?p=522</guid>
		<description><![CDATA[Problem:
How to find big files on linux?
Solution:

 find / -type f -size +50000k

This will find files bigger than 50MB (50000k)
]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong></p>
<p>How to find big files on linux?</p>
<p><strong>Solution:</strong></p>
<pre class="brush: bash;">
 find / -type f -size +50000k
</pre>
<p>This will find files bigger than 50MB (50000k)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.overflow.biz/blog/lang/en-us/2011/04/02/finding-big-files-on-linux/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert Object to Array in php</title>
		<link>http://www.overflow.biz/blog/lang/en-us/2010/12/29/convert-object-to-array-in-php?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=convert-object-to-array-in-php</link>
		<comments>http://www.overflow.biz/blog/lang/en-us/2010/12/29/convert-object-to-array-in-php#comments</comments>
		<pubDate>Wed, 29 Dec 2010 12:29:19 +0000</pubDate>
		<dc:creator>z3n</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[toarray]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.overflow.biz/blog/?p=518</guid>
		<description><![CDATA[Problem:
How to convert a generic object into an array?
Solution:
I&#8217;ve wrote this to convert simple xml objects into array, works pretty good.

function toArray($obj) {
	if (is_object($obj))
		$obj = (array)$obj;

	if (is_array($obj)) {
		foreach ($obj as &#38;$val)
			$val = toArray($val);
	} else { // if this is not an array so it's a string
		$obj = (string)$obj;
	}

	return $obj;
}

]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong><br />
How to convert a generic object into an array?</p>
<p><strong>Solution:</strong><br />
I&#8217;ve wrote this to convert simple xml objects into array, works pretty good.</p>
<pre class="brush: php;">
function toArray($obj) {
	if (is_object($obj))
		$obj = (array)$obj;

	if (is_array($obj)) {
		foreach ($obj as &#38;$val)
			$val = toArray($val);
	} else { // if this is not an array so it's a string
		$obj = (string)$obj;
	}

	return $obj;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.overflow.biz/blog/lang/en-us/2010/12/29/convert-object-to-array-in-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>email validator snippet</title>
		<link>http://www.overflow.biz/blog/lang/en-us/2010/12/04/email-validator-snippet?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=email-validator-snippet</link>
		<comments>http://www.overflow.biz/blog/lang/en-us/2010/12/04/email-validator-snippet#comments</comments>
		<pubDate>Sat, 04 Dec 2010 19:27:34 +0000</pubDate>
		<dc:creator>z3n</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[validate]]></category>

		<guid isPermaLink="false">http://www.overflow.biz/blog/?p=515</guid>
		<description><![CDATA[Problem:
How to validate an email using php?
Solution:
I&#8217;m posting this function because i made it to have older php compatibility.

function email_validator($email) {
	return function_exists(&#34;filter_var&#34;) ?
			filter_var($email, FILTER_VALIDATE_EMAIL)
		: // if filter_var is not defined (php &#60; 5.2), we will emulate php's core here
			!empty($email) &#38;&#38; strlen($email) &#60;= 320 &#38;&#38;
			/**
			 * preg info:
			 *
			 * Copyright © Michael Rushton 2009-10
			 * [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong></p>
<p>How to validate an email using php?</p>
<p><strong>Solution:</strong></p>
<p>I&#8217;m posting this function because i made it to have older php compatibility.</p>
<pre class="brush: php;">
function email_validator($email) {
	return function_exists(&#34;filter_var&#34;) ?
			filter_var($email, FILTER_VALIDATE_EMAIL)
		: // if filter_var is not defined (php &#60; 5.2), we will emulate php's core here
			!empty($email) &#38;&#38; strlen($email) &#60;= 320 &#38;&#38;
			/**
			 * preg info:
			 *
			 * Copyright © Michael Rushton 2009-10
			 * http://squiloople.com/
			 *
			 * more at: http://svn.php.net/viewvc/php/php-src/trunk/ext/filter/logical_filters.c?view=markup
			 */
			preg_match(&#34;/^(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)&#124;(?:\\x22?[^\\x5C\\x22]\\x22?)){255,})(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)&#124;(?:\\x22?[^\\x5C\\x22]\\x22?)){65,}@)(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)&#124;(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]&#124;(?:\\x5C[\\x00-\\x7F]))*\\x22))(?:\\.(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)&#124;(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]&#124;(?:\\x5C[\\x00-\\x7F]))*\\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)&#124;(?:(?:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)&#124;(?:\\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})&#124;(?:(?!(?:.*[a-f0-9][:\\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))&#124;(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)&#124;(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])&#124;(?:2[0-4][0-9])&#124;(?:1[0-9]{2})&#124;(?:[1-9]?[0-9]))(?:\\.(?:(?:25[0-5])&#124;(?:2[0-4][0-9])&#124;(?:1[0-9]{2})&#124;(?:[1-9]?[0-9]))){3}))\\]))$/iD&#34;, $email)
	;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.overflow.biz/blog/lang/en-us/2010/12/04/email-validator-snippet/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL full database search</title>
		<link>http://www.overflow.biz/blog/lang/en-us/2010/12/04/mysql-full-database-search?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=mysql-full-database-search</link>
		<comments>http://www.overflow.biz/blog/lang/en-us/2010/12/04/mysql-full-database-search#comments</comments>
		<pubDate>Sat, 04 Dec 2010 18:47:12 +0000</pubDate>
		<dc:creator>z3n</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://www.overflow.biz/blog/?p=511</guid>
		<description><![CDATA[Problem:
You need to find a entry or a specific value that&#8217;s into a table from a database, but you don&#8217;t know what is the table neither the database for sure.
Solution:
Use my happy mysql full database search script.
It&#8217;s so fun when all you gotta do is type a single command.
download mysql full database search script
]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong></p>
<p>You need to find a entry or a specific value that&#8217;s into a table from a database, but you don&#8217;t know what is the table neither the database for sure.</p>
<p><strong>Solution:</strong></p>
<p>Use my happy mysql full database search script.<br />
It&#8217;s so fun when all you gotta do is type a single command.</p>
<p><a href='http://www.overflow.biz/blog/wp-content/uploads/2010/12/mysql_full_database_search.rar'>download mysql full database search script</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.overflow.biz/blog/lang/en-us/2010/12/04/mysql-full-database-search/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SVN folder cleaning (svn wipe)</title>
		<link>http://www.overflow.biz/blog/lang/en-us/2010/12/04/svn-folder-cleaning-svn-wipe?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=svn-folder-cleaning-svn-wipe</link>
		<comments>http://www.overflow.biz/blog/lang/en-us/2010/12/04/svn-folder-cleaning-svn-wipe#comments</comments>
		<pubDate>Sat, 04 Dec 2010 13:37:07 +0000</pubDate>
		<dc:creator>z3n</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[wipe]]></category>

		<guid isPermaLink="false">http://www.overflow.biz/blog/?p=509</guid>
		<description><![CDATA[Problem:
You did a svn checkout on this nice project but now you don&#8217;t want that .svn folders all over the place, after all you won&#8217;t be commiting it. Suddenly you find out that there&#8217;s thousands of folders with thousands of files.
Solution:
I wrote this little php cli script to fix this:

&#60;?php

// (c) z3n - R1V1@101203 - [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong></p>
<p>You did a svn checkout on this nice project but now you don&#8217;t want that .svn folders all over the place, after all you won&#8217;t be commiting it. Suddenly you find out that there&#8217;s thousands of folders with thousands of files.</p>
<p><strong>Solution:</strong></p>
<p>I wrote this little php cli script to fix this:</p>
<pre class="brush: php;">
&#60;?php

// (c) z3n - R1V1@101203 - www.overflow.biz - rodrigo.orph@gmail.com

function _o($msg) {
	echo &#34;\r&#34; . substr($msg,0, 79) . str_repeat(&#34; &#34;, 79 - strlen($msg));
}

function rddir($dir) { /* v2.17 */
	global $tfile,$tdir;

	if (is_dir($dir)) {
		if ($dh = opendir($dir)) {
			while (($file = readdir($dh)) !== false) {
				if ($file != &#34;.&#34; &#38;&#38; $file != &#34;..&#34;) {
					if (is_dir($dir . $file))
						$tdir[] = $dir . $file;
					else
						$tfile[] = $file;
				}
			}
			closedir($dh);
		}
	}
}

if (!isset($argv[1]))
	die(&#34;Usage: &#34; . $_SERVER['PHP_SELF'] . &#34; &#60;path/to/svn_root/&#62;&#34;);

// browse dirs searching for .svn

for (
	$tdir = array($argv[1]),
	$tfile = array(),
	$svn = array(),
	$i = 0;$i &#60; count($tdir);$i++)
{
	rddir($tdir[$i]);
	_o(&#34;Reading: &#34;.$tdir[$i].&#34; ...&#34;);

	foreach ($tfile as $entry) {
		if ($entry != &#34;.&#34; &#38;&#38; $entry != &#34;..&#34;) {
			$fn = $tdir[$i] . (PHP_OS == &#34;WINNT&#34; ? &#34;\\&#34; : &#34;/&#34;) . $entry;
			if ($entry == &#34;.svn&#34; &#38;&#38; !in_array($fn, $svn))
				$svn[] = $fn;

			if (is_dir($fn) &#38;&#38; $entry != &#34;.svn&#34;)
				$tdir[] = $fn;
		}
	}

	$tfile = array();
}

_o(&#34;Found: &#34; . count($svn) . &#34; .svn folders, collecting files...&#34;);

$files = array();
$dirs = array();
$t = 0;

// collect files from .svn folders

foreach ($svn as $dir) {
	for ($tdir = array($dir), $tfile = array(),$i = 0;$i &#60; count($tdir);$i++) {
		rddir($tdir[$i]);
		_o(&#34;[&#34; . $t . &#34;] - Collecting: &#34;. $tdir[$i] .&#34;...&#34;);

		foreach ($tfile as $entry) {
			if ($entry != &#34;.&#34; &#38;&#38; $entry != &#34;..&#34;) {
				$fn = $tdir[$i] . (PHP_OS == &#34;WINNT&#34; ? &#34;\\&#34; : &#34;/&#34;) . $entry;
				$t++;

				if (is_dir($fn)) {
					$tdir[] = $fn;
					$dirs[] = $fn;
				} else {
					$files[] = $fn;
				}
			}
		}
	}
}

$i = count($files) + count($dirs) + count($svn);

// delete files

foreach ($files as $file) {
	_o(&#34;[&#34; . $i . &#34;] Deleting Files: &#34; . $file);
	unlink($file);
	$i--;
}

// delete subfolders

rsort($dirs);

foreach ($dirs as $dir) {
	_o(&#34;[&#34; . $i . &#34;] Deleting Dir: &#34; . $dir);
	rmdir($dir);
	$i--;
}

// delete root .svn folders

foreach ($svn as $dir) {
	_o(&#34;[&#34; . $i . &#34;] Deleting Roots: &#34; . $dir);
	rmdir($dir);
	$i--;
}

echo &#34;\nDone!&#34;;

?&#62;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.overflow.biz/blog/lang/en-us/2010/12/04/svn-folder-cleaning-svn-wipe/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Memcached PHP Class</title>
		<link>http://www.overflow.biz/blog/lang/en-us/2010/11/21/memcached-php-class?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=memcached-php-class</link>
		<comments>http://www.overflow.biz/blog/lang/en-us/2010/11/21/memcached-php-class#comments</comments>
		<pubDate>Sun, 21 Nov 2010 22:48:52 +0000</pubDate>
		<dc:creator>z3n</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.overflow.biz/blog/?p=507</guid>
		<description><![CDATA[Problem:
I needed a realiable memcached php class. I know there should be a bunch of them around, but i wanted to write my own anyway, just for fun maybe.
Solution:

&#60;?php

/**
 * WSA Memcached
 *
 * @category Class
 * @package  WSA/Memcached/
 * @author   Rodrigo Moraes Orph &#60;rodrigo.orph@gmail.com&#62;
 * @license  Copyright 2010 http://www.overflow.biz
 * [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong></p>
<p>I needed a realiable memcached php class. I know there should be a bunch of them around, but i wanted to write my own anyway, just for fun maybe.</p>
<p><strong>Solution:</strong></p>
<pre class="brush: php;">
&#60;?php

/**
 * WSA Memcached
 *
 * @category Class
 * @package  WSA/Memcached/
 * @author   Rodrigo Moraes Orph &#60;rodrigo.orph@gmail.com&#62;
 * @license  Copyright 2010 http://www.overflow.biz
 * @version  1.01
 * @note     This is a standalone script, it will be able to work without all the
 *           rest of WSA framework.
 */

interface iWSAMemcached {
	public function set($key, $val);
	public function get($key);
	public function delete($key);
	public function increment($key);
	public function decrement($key);
	public function flush();
	public function debug($bool);
	public function addServer($host, $port);
}

class WSAMemcached implements iWSAMemcached {
	/**
	 * Memcache_id key prefix
	 * Will by applied to all memcache fetch/save related functions
	 *
	 * @string
	 */
	public $key_prefix;

	/**
	 * Always serialize a set string
	 * This will also speed up get function by avoiding is_serialized function
	 *
	 * @bool default true
	 */
	public $always_serialize = true;

	/**
	 * Default Expiration Time of a set in seconds
	 *
	 * @int default 86400
	 */
	public $expires = 86400;

	/**
	 * Connection Max Retries
	 * Sets a limit to retry when connection fails
	 *
	 * @int default 10
	 */
	public $max_retry = 10;

	/**
	 * Connection Retry Delay
	 * Sets the delay in ms between connection retries
	 *
	 * @int default 2500
	 */
	public $retry_delay = 2500;

	/**
	 * Connection Timeout in seconds
	 *
	 * @int default 30
	 */
	public $timeout = 30;

	/**
	 * Enables Persistent Connection Mode
	 *
	 * @bool default false
	 */
	public $pmode = false;

	/**
	 * Change key process hash algorithm
	 *
	 * @string hash() compatible algo default md5 (eg: md5 , sha1 , crc32 , haval160 etc)
	 */
	public $key_hash = &#34;md5&#34;;

	/**
	 * Connected Flag
	 *
	 * @bool default true
	 */
	protected $connected = false;

	/**
	 * Memcached object
	 *
	 * @object memcache
	 */
	protected $memcache;

	/**
	 * Memcached host
	 *
	 * @string
	 */
	protected $host;

	/**
	 * Memcached port
	 *
	 * @int
	 */
	protected $port;

	/**
	 * Current retry number
	 *
	 * @int
	 */
	private $retry = 0;

	/**
	 * Constructor
	 *
	 * @param $host string memcached host
	 * @param $port int memcached port
	 * @opt param $key_prefix string memcached key prefix
	 */
	public function __construct($host, $port, $key_prefix = &#34;&#34;) {
		$this-&#62;host = $host;
		$this-&#62;port = $port;
		$this-&#62;key_prefix = $key_prefix;
	}

	/**
	 * Destruct
	 *
	 * Will try to gracefully close memcached connection
	 */
	public function __destruct() {
		$this-&#62;close();
	}

	/**
	 * Add Server to memcache cluster
	 *
	 * @requires memcache 2.0.0+
	 *
	 * @param $host string memcached host
	 * @param $port int memcached port
	 *
	 * @return $bool
	 */
	public function addServer($host, $port, $persistent = true, $weight = 0, $timeout = 1, $retry_interval = 15, $status = false, $failure_callback = null) {
		return $this-&#62;memcache-&#62;addServer(
			$host,
			$post,
			$persistent,
			$weight,
			$timeout,
			$retry_interval,
			$status,
			$failure_callback
		);
	}

	/**
	 * Stores a value on memcache
	 *
	 * @param $key string memcache key
	 * @param $val mixed value to be stored
	 * @opt param $flag mixed memcache flag
	 * @opt param $expires int cache expiration in seconds
	 *
	 * @return bool
	 */
	public function set($key, $val, $flag = MEMCACHE_COMPRESSED, $expires = 0, $no_serialize = false) {
		if (empty($expires) &#124;&#124; intval($expires) &#60;= 0)
			$expires = $this-&#62;expires;

		$this-&#62;connect();

		// check key
		if (empty($key))
			throw new Expection(&#34;Empty key when setting a value&#34;, 2);

		// encode key
		$key = $this-&#62;key_process($key);

		// make sure val is a valid entry
		if (!$no_serialize &#38;&#38; ($this-&#62;always_serialize &#124;&#124; is_array($val)))
			$val = serialize($val);

		return $this-&#62;memcache-&#62;set($key, $val, $flag, $expires);
	}

	/**
	 * Fetches a value on memcache
	 *
	 * @param $key string memcache key
	 *
	 * @return mixed serialized values will be unserialized automatically
	 */
	public function get($key, $no_unserialize = false) {
		if (empty($key))
			throw new Expection(&#34;Empty key when fetching a value&#34;, 3);

		$this-&#62;connect();

		// encode key
		$key = $this-&#62;key_process($key);

		// fetch value
		$val = $this-&#62;memcache-&#62;get($key);

		if (!$no_unserialize &#38;&#38; ($this-&#62;always_serialize &#124;&#124; $this-&#62;is_serialized($val)))
			return unserialize($val);
		else
			return $val;
	}

	/**
	 * Deletes a vlue from memcache
	 *
	 * @param $key string memcache key
	 * @opt param $timeout int delete timeout
	 * @note timeout don't work with memcached version i've tested.
	 *
	 * @return bool delete result
	 */
	public function delete($key, $timeout = 0) {
		if (empty($key))
			throw new Expection(&#34;Empty key when deleting a value&#34;, 5);

		if (empty($timeout) &#124;&#124; intval($timeout) &#60;= 0)
			$timeout = 1;

		$this-&#62;connect();

		// encode key
		$key = $this-&#62;key_process($key);

		// delete value
		return $this-&#62;memcache-&#62;delete($key); //, $timeout);
	}

	/**
	 * Increment a int value
	 *
	 * @param $key string memcache key
	 *
	 * @return int current value
	 */
	public function increment($key, $val = 1) {
		if (empty($key))
			throw new Expection(&#34;Empty key when incrementing a value&#34;, 5);

		if (empty($val))
			$val = 1;

		$this-&#62;connect();

		// encode key
		$key = $this-&#62;key_process($key);

		// increment value
		return $this-&#62;memcache-&#62;increment($key, abs($val));
	}

	/**
	 * Increment a int value
	 *
	 * @param $key string memcache key
	 *
	 * @return int current value
	 */
	public function decrement($key, $val = 1) {
		if (empty($key))
			throw new Expection(&#34;Empty key when decrementing a value&#34;, 6);

		if (empty($val))
			$val = 1;

		$this-&#62;connect();

		// encode key
		$key = $this-&#62;key_process($key);

		// increment value
		return $this-&#62;memcache-&#62;decrement($key, abs($val));
	}

	/**
	 * Flush - Mark all entries as expired
	 *
	 * @return bool
	 */
	public function flush() {
		$this-&#62;connect();

		return $this-&#62;memcache-&#62;flush();
	}

	/**
	 * Debug - Enables/Disables Memcache debug mode
	 *
	 * @note This is a global function
	 *
	 * @return bool
	 */
	public function debug($bool) {
		return memcache_debug($bool ? &#34;on&#34; : &#34;off&#34;);
	}

	/**
	 * Main memcache connector
	 * Will try to connect to memcached, on fail retries a specified number of
	 * times with a configurable delay between attempts; If a connection is
	 * already established will return it's state (bool);
	 *
	 * @return bool
	 */
	protected function connect() {
		if (!$this-&#62;connected) {
			$this-&#62;memcache = new Memcache();

			// connect to memcache
			if ($this-&#62;pmode)
				$ret = $this-&#62;memcache-&#62;pconnect($this-&#62;host, $this-&#62;port, $this-&#62;timeout);
			else
				$ret = $this-&#62;memcache-&#62;connect($this-&#62;host,  $this-&#62;port, $this-&#62;timeout);

			if (!$ret &#38;&#38; $this-&#62;retry &#60; $this-&#62;max_retry) {
				$this-&#62;retry++;
				usleep($this-&#62;retry_delay);
				return $this-&#62;connect();
			} elseif (!$ret) {
				throw new Exception(&#34;Unable to connect to memcached - Tried: &#34;.$this-&#62;max_retry.&#34; times&#34;, 1);
			}

			$this-&#62;connected = $ret;
			return $this-&#62;connected;
		}
	}

	/**
	 * Main memcache connection close
	 *
	 * @return bool
	 */
	protected function close() {
		if ($this-&#62;connected) {
			$this-&#62;memcache-&#62;close();
			$this-&#62;connected = false;
			$this-&#62;memcache = null;

			return true;
		}

		return false;
	}

	/**
	 * Process a key value adding prefix and encoding it to a suitable hash
	 *
	 * @param $key string key value
	 *
	 * @return encoded key value
	 */
	protected function key_process($key) {
		if (empty($key))
			throw new Expection(&#34;Empty key when processing key.&#34;, 4);

		return hash($this-&#62;key_hash, $this-&#62;key_prefix.$key);
	}

	/**
	 * Checks if a variable is serialized
	 *
	 * @param $val mixed
	 * @opt param &#38;$result bool return value
	 *
	 * @return bool
	 */
	protected function is_serialized($value, &#38;$result = null) {
		// Bit of a give away this one
		if (!is_string($value)) {
			return false;
		}

		// Serialized false, return true. unserialize() returns false on an
		// invalid string or it could return false if the string is serialized
		// false, eliminate that possibility.
		if ($value === 'b:0;') {
			$result = false;
			return true;
		}

		$length = strlen($value);
		$end = '';

		switch ($value[0]) {
			case 's':
				if ($value[$length - 2] !== '&#34;') {
					return false;
				}
			case 'b':
			case 'i':
			case 'd':
				// This looks odd but it is quicker than isset()ing
				$end .= ';';
			case 'a':
			case 'O':
				$end .= '}';

			if ($value[1] !== ':') {
				return false;
			}

			switch ($value[2]) {
				case 0:
				case 1:
				case 2:
				case 3:
				case 4:
				case 5:
				case 6:
				case 7:
				case 8:
				case 9:
				break;

				default:
					return false;
			}
			case 'N':
				$end .= ';';

				if ($value[$length - 1] !== $end[0]) {
					return false;
				}
			break;

			default:
				return false;
		}

		if (($result = @unserialize($value)) === false) {
			$result = null;
			return false;
		}
		return true;
	}
}
</pre>
<p><strong>More:</strong></p>
<p><a href="http://www.phpclasses.org/package/6631-PHP-Memcached-Class.html" target="_blank">PHPClasses.org Project</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.overflow.biz/blog/lang/en-us/2010/11/21/memcached-php-class/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

