<?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>The way I see it</title>
	<atom:link href="http://damiansromek.pl/feed/" rel="self" type="application/rss+xml" />
	<link>http://damiansromek.pl</link>
	<description>Website development (PHP, JS, MySQL) by Damian Sromek</description>
	<lastBuildDate>Sat, 31 Mar 2012 09:36:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>[How to] Speed up Windows 7 boot-up time &#8211; turn off media sharing</title>
		<link>http://damiansromek.pl/2012/03/31/how-to-speed-up-windows-7-boot-up-time-turn-off-media-sharing/</link>
		<comments>http://damiansromek.pl/2012/03/31/how-to-speed-up-windows-7-boot-up-time-turn-off-media-sharing/#comments</comments>
		<pubDate>Sat, 31 Mar 2012 09:33:04 +0000</pubDate>
		<dc:creator>pAq</dc:creator>
				<category><![CDATA[How to]]></category>
		<category><![CDATA[OS]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://damiansromek.pl/?p=89</guid>
		<description><![CDATA[How to find out what's using resources? Since some time I've noticed that after logging in to Windows 7 something is doing a lot of HDD I/O operations for like 3 minutes. This was of course making everything else running much slower. Especially running any app for the first time was taking much longer than [...]]]></description>
			<content:encoded><![CDATA[<h2>How to find out what's using resources?</h2>
<p>Since some time I've noticed that after logging in to Windows 7 something is doing <strong>a lot of HDD I/O operations for like 3 minutes</strong>.</p>
<p>This was of course making everything else running much slower. Especially running any app for the first time was taking much longer than it should.</p>
<p>After checking in "<strong>Performance Monitor</strong>" (standard Windows tool) I've noticed that <strong>Wmpnetwk.exe</strong> process is performing most of the HDD I/O operations.<br />
This is part of the Windows Media Player which lets you share media through network. <a href="http://windows.microsoft.com/en-US/windows-vista/Sharing-media-on-a-network-using-Windows-Media-Player" target="_blank">@see Windows media sharing</a></p>
<p>When you have a lot of media (pictures, movies) it takes long to scan for changes etc. This is what was taking so long after system start-up. I'm not using this feature anyway so I've decided to turn it off.</p>
<h2>How to disable Windows media sharing?</h2>
<ol>
<li>Run services.msc</li>
<li>Stop and disable  "Windows Media Player Network Sharing" service</li>
</ol>
<p>You can <a href="http://www.hkactivity.com/wmpnetwk-exe-disable-and-fix-high-cpu-usage-error-windows-7/" target="_blank">read this post</a> for more details (screenshots).</p>
<div class="twttr_button">
				<a href="http://twitter.com/share?url=http://damiansromek.pl/2012/03/31/how-to-speed-up-windows-7-boot-up-time-turn-off-media-sharing/&text=[How to] Speed up Windows 7 boot-up time - turn off media sharing" target="_blank" title="Click here if you liked this article.">
					<img src="http://damiansromek.pl/wp-content/plugins/twitter-plugin/images/twitt.gif" alt="Twitt" />
				</a>
			</div>]]></content:encoded>
			<wfw:commentRss>http://damiansromek.pl/2012/03/31/how-to-speed-up-windows-7-boot-up-time-turn-off-media-sharing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Presentation] Thin controllers &#8211; fat models.</title>
		<link>http://damiansromek.pl/2012/03/21/presentation-thin-controllers-fat-models/</link>
		<comments>http://damiansromek.pl/2012/03/21/presentation-thin-controllers-fat-models/#comments</comments>
		<pubDate>Wed, 21 Mar 2012 19:21:24 +0000</pubDate>
		<dc:creator>pAq</dc:creator>
				<category><![CDATA[Framework]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://damiansromek.pl/?p=78</guid>
		<description><![CDATA[Thin controllers - fat models (Proper code structure for MVC) View more presentations from damiansromek]]></description>
			<content:encoded><![CDATA[<div style="width:425px" id="__ss_12104655"> <strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/damiansromek/thin-controllers-fat-models-proper-code-structure-for-mvc" title="Thin controllers - fat models (Proper code structure for MVC)" target="_blank">Thin controllers - fat models (Proper code structure for MVC)</a></strong> <iframe src="http://www.slideshare.net/slideshow/embed_code/12104655" width="425" height="355" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
<div style="padding:5px 0 12px"> View more <a href="http://www.slideshare.net/" target="_blank">presentations</a> from <a href="http://www.slideshare.net/damiansromek" target="_blank">damiansromek</a> </div>
</p></div>
<div class="twttr_button">
				<a href="http://twitter.com/share?url=http://damiansromek.pl/2012/03/21/presentation-thin-controllers-fat-models/&text=[Presentation] Thin controllers - fat models. " target="_blank" title="Click here if you liked this article.">
					<img src="http://damiansromek.pl/wp-content/plugins/twitter-plugin/images/twitt.gif" alt="Twitt" />
				</a>
			</div>]]></content:encoded>
			<wfw:commentRss>http://damiansromek.pl/2012/03/21/presentation-thin-controllers-fat-models/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHPCon PL 2011 &#8211; Safety of web applications (Przemysław Pawliczuk)</title>
		<link>http://damiansromek.pl/2011/11/05/phpcon-pl-2011-safety-of-web-applications-przemyslaw-pawliczuk/</link>
		<comments>http://damiansromek.pl/2011/11/05/phpcon-pl-2011-safety-of-web-applications-przemyslaw-pawliczuk/#comments</comments>
		<pubDate>Fri, 04 Nov 2011 23:05:30 +0000</pubDate>
		<dc:creator>pAq</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://damiansromek.pl/?p=72</guid>
		<description><![CDATA[What should you keep in your mind to make your web app more secure? Check file content when you receive it through $_FILES. Check if it contains "&#60;?php". Remember that image EXIF can be dangerous. Salt passwords. Do not authenticate on the client side. Write down basic procedures what would you do if your application [...]]]></description>
			<content:encoded><![CDATA[<p>What should you keep in your mind to make your web app more secure?</p>
<ul>
<li>Check file content when you receive it through $_FILES. Check if it contains "&lt;?php".</li>
<li>Remember that image EXIF can be dangerous.</li>
<li>Salt passwords.</li>
<li>Do not authenticate on the client side.</li>
<li>Write down basic procedures what would you do if your application has been hacked.</li>
<li>Let people in your company use the app for the first time to play and try to break it.</li>
<li>Separate development from production machines on every aspect.</li>
</ul>
<div class="twttr_button">
				<a href="http://twitter.com/share?url=http://damiansromek.pl/2011/11/05/phpcon-pl-2011-safety-of-web-applications-przemyslaw-pawliczuk/&text=PHPCon PL 2011 - Safety of web applications (Przemysław Pawliczuk)" target="_blank" title="Click here if you liked this article.">
					<img src="http://damiansromek.pl/wp-content/plugins/twitter-plugin/images/twitt.gif" alt="Twitt" />
				</a>
			</div>]]></content:encoded>
			<wfw:commentRss>http://damiansromek.pl/2011/11/05/phpcon-pl-2011-safety-of-web-applications-przemyslaw-pawliczuk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHPCon PL 2011 &#8211; how to increase productivity of PHP programmer (Adam Puza)</title>
		<link>http://damiansromek.pl/2011/11/04/phpcon-pl-2011-how-to-increase-productivity-of-php-programmer-adam-puza/</link>
		<comments>http://damiansromek.pl/2011/11/04/phpcon-pl-2011-how-to-increase-productivity-of-php-programmer-adam-puza/#comments</comments>
		<pubDate>Fri, 04 Nov 2011 22:56:00 +0000</pubDate>
		<dc:creator>pAq</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[programmer performance]]></category>
		<category><![CDATA[programmer tips]]></category>

		<guid isPermaLink="false">http://damiansromek.pl/?p=68</guid>
		<description><![CDATA[You can see whole presentation here (in polish). Adam Puza prepared also a page related to that where you can find links to useful tools etc. So how can we increase our productivity? Use mouse as rare as possible. Try to do everything just with keyboard. Use clipboard manager, eg. ClipX Keep you passwords in [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright" title="AutoHotkey" src="http://www.autohotkey.com/docs/images/AutoHotkey_logo.gif" alt="AutoHotkey" width="228" height="133" />You can see whole presentation <a href="http://www.slideshare.net/adamhmetal/zwikszanie-produktywnoci-programisty-php-v2">here (in polish)</a>. Adam Puza prepared also a <a href="http://webdemon.org.pl/zppphp.php">page related</a> to that where you can find links to useful tools etc.</p>
<p>So how can we increase our productivity?</p>
<ul>
<li>Use mouse as rare as possible. Try to do everything just with keyboard.</li>
<li>Use clipboard manager, eg. ClipX</li>
<li>Keep you passwords in one place, eg. Keypass</li>
<li>Use shortcut keys, eg. with AutoHotkey</li>
<li>Learn IDE shortcut keys. Search files using keyboard, not mouse.</li>
<li>Use virtual machines when you have to set up specialized environment to work with some project.</li>
</ul>
<p>What's the best way to learn shortcut keys?</p>
<ol>
<li>Do something using mouse.</li>
<li>Next check how can it be done with just a keyboard.</li>
<li>Revert action and do it using a keyboard.</li>
</ol>
<p>You can read more interesting things out of his presentation.</p>
<div class="twttr_button">
				<a href="http://twitter.com/share?url=http://damiansromek.pl/2011/11/04/phpcon-pl-2011-how-to-increase-productivity-of-php-programmer-adam-puza/&text=PHPCon PL 2011 - how to increase productivity of PHP programmer (Adam Puza)" target="_blank" title="Click here if you liked this article.">
					<img src="http://damiansromek.pl/wp-content/plugins/twitter-plugin/images/twitt.gif" alt="Twitt" />
				</a>
			</div>]]></content:encoded>
			<wfw:commentRss>http://damiansromek.pl/2011/11/04/phpcon-pl-2011-how-to-increase-productivity-of-php-programmer-adam-puza/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHPCon PL 2011 – Yii Framework &#8211; just another MVC or maybe small revolution? (Krzysztof Maziarz)</title>
		<link>http://damiansromek.pl/2011/10/26/phpcon-pl-2011-%e2%80%93-yii-framework-just-another-mvc-or-maybe-small-revolution-krzysztof-maziarz/</link>
		<comments>http://damiansromek.pl/2011/10/26/phpcon-pl-2011-%e2%80%93-yii-framework-just-another-mvc-or-maybe-small-revolution-krzysztof-maziarz/#comments</comments>
		<pubDate>Wed, 26 Oct 2011 20:54:41 +0000</pubDate>
		<dc:creator>pAq</dc:creator>
				<category><![CDATA[Framework]]></category>
		<category><![CDATA[php framework]]></category>
		<category><![CDATA[phpcon pl 2011]]></category>
		<category><![CDATA[yii]]></category>

		<guid isPermaLink="false">http://damiansromek.pl/?p=63</guid>
		<description><![CDATA[The author of the presentation was trying to convince us that Yii Framework is all that we ever needed for website development. All features of that framework will let you do anything you want and to do it really fast. I've heard of that framework many months (or maybe even few years) ago. I've looked [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.yiiframework.com/css/img/logo.png"><img class="alignright" title="Yii logo" src="http://www.yiiframework.com/css/img/logo.png" alt="Yii logo" width="284" height="64" /></a><br />
The author of the presentation was trying to convince us that <a href="http://www.yiiframework.com/" target="_blank">Yii Framework</a> is all that we ever needed for website development.<br />
<a href="http://www.yiiframework.com/features/" target="_blank">All features of that framework</a> will let you do anything you want and to do it really fast.</p>
<p>I've heard of that framework many months (or maybe even few years) ago. I've looked at it a bit but I was not convinced it's so much better than the other frameworks.<br />
After that presentation I've decided to take a bit closer look. That's what I think about it.</p>
<p><span id="more-63"></span><span>Pros:</span></p>
<ul>
<li>It lets you create a web application really fast. A lot of the code can be autogenerated so you have to just adjust it to your needs.</li>
<li>Code easy to understand and use. Behaviors.</li>
<li>Prepared for testing (PHPUnit).</li>
<li>Good documentation. Sample applications included so you can see in practice how an app looks like.</li>
</ul>
<p>Cons:</p>
<ul>
<li>Active record - it's easy to use but it often does not work efficient enough for heavy loaded apps.</li>
<li>Not as "loosely coupled" as some would like it to be.</li>
<li>No dependency injection container.</li>
</ul>
<p>After just few hours spend on getting familiar with that framework I could recommend it for small or medium projects.<br />
If you need to create fast not so complex webpage this framework will definitely help you with that.<br />
It's using many where known solutions (eg. Active Record, MVC) so person familiar with that should not have problems with starting using Yii.</p>
<p>I would not recommend it for big projects where you want things really decoupled, independent and testable.<br />
I think dependency injection container, Doctrine 2, totally independent parts (modules, bundles - whatever you call it) that can be easy configured (eg. with annotations) are what makes your life easy and beautiful.<br />
Yes, I'm thinking about <a href="http://symfony.com/" target="_blank">Symfony 2</a> (and maybe <a href="http://framework.zend.com/wiki/pages/viewpage.action?pageId=42303506" target="_blank">Zend Framework 2</a> soon) when I think about framework for big projects.</p>
<p>I think Yii authors will change it so it will look more like "modern" frameworks (eg. Symfony 2) if they would want it to be widely used in big projects. Right now Yii is using well known solutions that are also well known to be NOT enough when there's huge amount of code, modules, functionality etc.</p>
<p>But I haven't used Yii. Maybe I'm wrong. But this framework definitely did not make such a big and good impression on me as <a href="http://symfony.com/" target="_blank">Symfony 2</a> did.</p>
<div class="twttr_button">
				<a href="http://twitter.com/share?url=http://damiansromek.pl/2011/10/26/phpcon-pl-2011-%e2%80%93-yii-framework-just-another-mvc-or-maybe-small-revolution-krzysztof-maziarz/&text=PHPCon PL 2011 – Yii Framework - just another MVC or maybe small revolution? (Krzysztof Maziarz)" target="_blank" title="Click here if you liked this article.">
					<img src="http://damiansromek.pl/wp-content/plugins/twitter-plugin/images/twitt.gif" alt="Twitt" />
				</a>
			</div>]]></content:encoded>
			<wfw:commentRss>http://damiansromek.pl/2011/10/26/phpcon-pl-2011-%e2%80%93-yii-framework-just-another-mvc-or-maybe-small-revolution-krzysztof-maziarz/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHPCon PL 2011 &#8211; Geolocation and Maps with PHP (Derick Rethans)</title>
		<link>http://damiansromek.pl/2011/10/24/phpcon-pl-2011-geolocation-and-maps-with-php-derick-rethans/</link>
		<comments>http://damiansromek.pl/2011/10/24/phpcon-pl-2011-geolocation-and-maps-with-php-derick-rethans/#comments</comments>
		<pubDate>Mon, 24 Oct 2011 19:35:53 +0000</pubDate>
		<dc:creator>pAq</dc:creator>
				<category><![CDATA[Maps and geolocation]]></category>
		<category><![CDATA[geolocation]]></category>
		<category><![CDATA[maps]]></category>
		<category><![CDATA[phpcon pl 2011]]></category>

		<guid isPermaLink="false">http://damiansromek.pl/?p=53</guid>
		<description><![CDATA[Derick Rethans has presented how we can use maps and geolocation in our web application. Of course maps are strictly GUI related so we need to have some knowledge about JavaScript. But sample code we saw on slides was really simple so no one should have problems with that. At least in basic use cases. [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright" title="OpenStreetMap logo" src="http://www.openstreetmap.org/images/osm_logo.png?1313181320" alt="OpenStreetMap logo" width="120" height="120" /><br />
<a href="http://derickrethans.nl/" target="_blank"><strong>Derick Rethans</strong></a> has presented how we can use maps and geolocation in our web application.</p>
<p>Of course maps are strictly GUI related so we need to have some knowledge about JavaScript. But sample code we saw on slides was really simple so no one should have problems with that. At least in basic use cases.</p>
<p>Almost all developers think about <strong>Google Maps</strong> when they consider solutions that will let them use maps on a site they are building.<br />
But as Derick showed us there are alternatives for Google Maps.<br />
He has mentioned <strong><a href="http://leaflet.cloudmade.com/" target="_blank">Leaflet</a></strong> (JavaScript library for interactive maps) and <strong><a href="http://www.openstreetmap.org/" target="_blank">OpenStreetMaps</a></strong> (open alternative for Google Maps).</p>
<p><a href="http://joind.in/talk/view/3919" target="_blank">You can see his <strong>presentation</strong> here. </a></p>
<p>According to Derick you can even host your own map service thanks to OpenStreetMaps data that can be downloaded for free.<br />
His presentation was full of "realtime demos" what made it really interesting.</p>
<p>Maps are just one think that we could use in our application but even plain data about places location could be used in many interesting ways.<br />
With a bit of imagination and creativity you can create amazing and interesting things.<br />
I can't wait to play with that some day.</p>
<div class="twttr_button">
				<a href="http://twitter.com/share?url=http://damiansromek.pl/2011/10/24/phpcon-pl-2011-geolocation-and-maps-with-php-derick-rethans/&text=PHPCon PL 2011 - Geolocation and Maps with PHP (Derick Rethans)" target="_blank" title="Click here if you liked this article.">
					<img src="http://damiansromek.pl/wp-content/plugins/twitter-plugin/images/twitt.gif" alt="Twitt" />
				</a>
			</div>]]></content:encoded>
			<wfw:commentRss>http://damiansromek.pl/2011/10/24/phpcon-pl-2011-geolocation-and-maps-with-php-derick-rethans/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[How to] Run PHPUnit tests using database 10x faster</title>
		<link>http://damiansromek.pl/2011/01/03/how-to-run-phpunit-tests-using-database-10x-faster/</link>
		<comments>http://damiansromek.pl/2011/01/03/how-to-run-phpunit-tests-using-database-10x-faster/#comments</comments>
		<pubDate>Mon, 03 Jan 2011 21:23:21 +0000</pubDate>
		<dc:creator>pAq</dc:creator>
				<category><![CDATA[How to]]></category>
		<category><![CDATA[PHPUnit]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[phpunit]]></category>
		<category><![CDATA[unit test]]></category>

		<guid isPermaLink="false">http://damian.pcunited.info/?p=3</guid>
		<description><![CDATA[Overview PHPUnit tests that are heavily using the database can run like 10x faster when you run the database from the RAMDisk. It's the easiest way I know to improve the speed of the tests execution. Problem - PHPUnit tests can run long time when they are using the database Project I'm contributing at my [...]]]></description>
			<content:encoded><![CDATA[<h2>Overview</h2>
<p>PHPUnit tests that are heavily using the database can run like 10x faster when you run the database from the RAMDisk.<br />
It's the easiest way I know to improve the speed of the tests execution.</p>
<h2>Problem - PHPUnit tests can run long time when they are using the database</h2>
<p>Project I'm contributing at my work - <a href="http://www.x-formation.com/#TabLicenseStatistics"><strong>License Statistics</strong></a> - uses quite a lot of unit tests.<br />
One of the reasons is that we try to do the Test Driven Development (TDD). But this method of creating the software has some drawbacks.</p>
<p>Right now we have something around <strong>1 000 tests</strong> that check around <strong>3 000 assertions</strong>. Much of them involve database operations. That's why <strong>running all tests on Windows machine can take up to 25 minutes</strong>.</p>
<p>Tests on Linux machine are much faster - around 7-10 minutes but we still need to run tests under Windows environment due to fact we have to support both platforms and we have to be sure that both of them work perfectly fine.<span id="more-3"></span></p>
<h2>Solution - put the Database on a very fast hard disk - RamDisk is the fastest</h2>
<p>I was "angry" (to say it nicely) that I have to wait almost half hour to see if my changes did not broke anything before I'll do a commit. Although we use continues integration it's nice to know that everything works fine on your machine. That's why I tried to figure out something that will speed up the tests execution.</p>
<p>It was not hard to see that the CPU has to wait for the HDD due to heavy database operations - database is cleaned after every test and initialized with small amount of needed, basic fixtures. Well maybe not every test, but every test that uses Doctrine somehow.</p>
<p>So the simplest  solution would be speeding up the HDD. Especially amount of the the I/O operations per second. There's no way to "overlock" the HDD like CPU so I tried to run the database from the pendrive. This gave me very small speed improvement (maybe because my pendrive is not so fast). But still I had to wait more than 20 minutes for the tests to finish.</p>
<p>Next idea was to "sacrifice" some part of the RAM for the purpose of creating a virtual HDD in that memory - so called <strong>RAM DISK</strong>.<br />
This solutions is known for years but I didn't see a really good reason till then to use it every day.</p>
<p><img class="alignnone" title="Dataram RAMDisk" src="http://memory.dataram.com/images/page-images/ramdisk-screenshot-lowres.jpg" alt="" width="320" height="252" /></p>
<p>Finally I used the <a href="http://memory.dataram.com/products-and-services/software/ramdisk">Dataram RAMDisk</a>. I <strong>created a 0,5 GB RAMDisk and put the database on it</strong>. I still have like 3,5 GB of RAM so it's enough for PHP development right now.</p>
<p>Thanks to that the <strong>tests are done in around 2 min 30 seconds</strong>! That's like <strong>10 times faster</strong> comparing to the time that was around 25 minutes when using regular HDD.<br />
<strong>I can say that it is worth for sure to sacrifice some part of the RAM to use the RAMDisk</strong>.</p>
<p><em>PS  <a href="http://memory.dataram.com/products-and-services/software/ramdisk">Dataram RAMDisk</a> is available as a freeware. It allows to create a disk up to 4 GB. For $10 you can buy a license that will allow you to create larger disk - up to 32 GB.</em></p>
<div class="twttr_button">
				<a href="http://twitter.com/share?url=http://damiansromek.pl/2011/01/03/how-to-run-phpunit-tests-using-database-10x-faster/&text=[How to] Run PHPUnit tests using database 10x faster" target="_blank" title="Click here if you liked this article.">
					<img src="http://damiansromek.pl/wp-content/plugins/twitter-plugin/images/twitt.gif" alt="Twitt" />
				</a>
			</div>]]></content:encoded>
			<wfw:commentRss>http://damiansromek.pl/2011/01/03/how-to-run-phpunit-tests-using-database-10x-faster/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>[Watch out] Zend_Date performance</title>
		<link>http://damiansromek.pl/2011/01/03/watch-out-zend_date-performance/</link>
		<comments>http://damiansromek.pl/2011/01/03/watch-out-zend_date-performance/#comments</comments>
		<pubDate>Mon, 03 Jan 2011 20:38:17 +0000</pubDate>
		<dc:creator>pAq</dc:creator>
				<category><![CDATA[How to]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[zend date]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[zend_date]]></category>

		<guid isPermaLink="false">http://damian.pcunited.info/?p=21</guid>
		<description><![CDATA[Problem - Zend_Date offers small performance I always try to use objects when I see they are giving me more flexibility than arrays or primitive types. During my work often I have to operate on dates so I use Zend_Date quite a lot - our project is based on the Zend Framework. But recently I've [...]]]></description>
			<content:encoded><![CDATA[<h2>Problem - Zend_Date offers small performance</h2>
<p>I always try to use objects when I see they are giving me more flexibility than arrays or primitive types.</p>
<p>During my work often I have to operate on dates so I use <a href="http://framework.zend.com/manual/en/zend.date.html">Zend_Date</a> quite a lot - our project is based on the <a href="http://framework.zend.com/">Zend Framework</a>. But recently I've run a <strong>profiler</strong> for one of the pages I created and I saw <strong>huge impact on the performance that Zend_Date had</strong>.</p>
<p>It did speed up development and made it easier but it also made the code much slower. <strong>Zend_Date Comparing with the plain <a href="http://php.net/manual/en/book.datetime.php">PHP DateTime</a> was like 5 to 10 times slower</strong>. <strong>Even Zend_Date::toString took quite large amount of CPU time</strong>.</p>
<h2>Solution - use PHP DateTime instead of Zend_Date</h2>
<p>Solution for that part of code was <strong>replacing the Zend_Date</strong> used in the loops (executed even couple hundred times) <strong>with DateTime</strong>. It was very simple. Also date operations like adding one day is very easy when we have DateTime object - we just need to pass a <a href="http://www.php.net/manual/en/class.dateinterval.php">DateInterval</a> into DateTime::add().</p>
<p>I'm still using Zend_Date for example as the method parameter but in code where I do many date operations I replace it with the DateTime. Thanks to that my scripts are executed much faster.</p>
<p><strong>Some of DateTime features are available since PHP &gt; 5.3</strong> but you can easily use DateTime with older PHP doing small changes in the code.</p>
<div class="twttr_button">
				<a href="http://twitter.com/share?url=http://damiansromek.pl/2011/01/03/watch-out-zend_date-performance/&text=[Watch out] Zend_Date performance" target="_blank" title="Click here if you liked this article.">
					<img src="http://damiansromek.pl/wp-content/plugins/twitter-plugin/images/twitt.gif" alt="Twitt" />
				</a>
			</div>]]></content:encoded>
			<wfw:commentRss>http://damiansromek.pl/2011/01/03/watch-out-zend_date-performance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Watch out] Doctrine_Query::fetchOne()</title>
		<link>http://damiansromek.pl/2010/12/21/watch-ou-doctrine_queryfetchone/</link>
		<comments>http://damiansromek.pl/2010/12/21/watch-ou-doctrine_queryfetchone/#comments</comments>
		<pubDate>Mon, 20 Dec 2010 23:13:07 +0000</pubDate>
		<dc:creator>pAq</dc:creator>
				<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[Watch out]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[Doctrine::fetchOne]]></category>

		<guid isPermaLink="false">http://damian.pcunited.info/?p=17</guid>
		<description><![CDATA[Problem - fetchOne does not fetch one record from the database Doctrine_Query has method which returns one row, it's called fetchOne. This method is quite useful because sometimes we just don't need all records that a query can return. But there's a "small" problem with that method. It does not fetch one record! Well maybe [...]]]></description>
			<content:encoded><![CDATA[<h2>Problem -<strong> fetchOne</strong> does not fetch one record from the database</h2>
<p>Doctrine_Query has method which returns one row, it's called <strong>fetchOne</strong>.<br />
This method is quite useful because sometimes we just don't need all records that a query can return.</p>
<p>But there's a "small" problem with that method. <strong>It does not fetch one record!</strong><br />
Well maybe it's not quite true because it returns one row, but at the back-end <strong>it fetches the whole collection</strong>.</p>
<p>Almost everyone knows that it's the worst solution to fetch all data into PHP from the database to make use just of one of the records. Sadly that is how the Doctrine_Query::fetchOne() really works.</p>
<h2>Solution</h2>
<p>Simple solution for that is to specify limit by hand, before executing fetchOne().</p>
<pre class="brush: js">/* @var $query Doctrine_Query */
$query-&gt;limit(1);
$record = $query-&gt;fetchOne();</pre>
<p><span id="more-17"></span><br />
Let's take a look at the source code of this method (Doctrine 1.2.3)</p>
<pre class="brush: js">  /**
     * fetchOne
     * Convenience method to execute the query and return the first item
     * of the collection.
     *
     * @param string $params        Query parameters
     * @param int $hydrationMode    Hydration mode: see Doctrine_Core::HYDRATE_* constants
     * @return mixed                Array or Doctrine_Collection, depending on hydration mode. False if no result.
     */
    public function fetchOne($params = array(), $hydrationMode = null)
    {
        $collection = $this-&gt;execute($params, $hydrationMode);

        if (is_scalar($collection)) {
            return $collection;
        }

        if (count($collection) === 0) {
            return false;
        }

        if ($collection instanceof Doctrine_Collection) {
            return $collection-&gt;getFirst();
        } else if (is_array($collection)) {
            return array_shift($collection);
        }

        return false;
    }</pre>
<p>As we can see there's <strong>no limit added to the query</strong>. This causes that <strong>the collection returned by execute() can be very huge</strong>. That may slow down our application a lot. And in the worst case it may even make it <strong>crash due to excessive memory and CPU usage</strong>.</p>
<p>Why this method does not apply limit? As far as I know the limit caused some problems in some cases and it was deleted from this method.</p>
<div class="twttr_button">
				<a href="http://twitter.com/share?url=http://damiansromek.pl/2010/12/21/watch-ou-doctrine_queryfetchone/&text=[Watch out] Doctrine_Query::fetchOne()" target="_blank" title="Click here if you liked this article.">
					<img src="http://damiansromek.pl/wp-content/plugins/twitter-plugin/images/twitt.gif" alt="Twitt" />
				</a>
			</div>]]></content:encoded>
			<wfw:commentRss>http://damiansromek.pl/2010/12/21/watch-ou-doctrine_queryfetchone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[How to] ExtJS stateful components &#8211; Ext.Panel collapsed/expanded state stored in cookies</title>
		<link>http://damiansromek.pl/2010/12/20/how-to-extjs-stateful-components/</link>
		<comments>http://damiansromek.pl/2010/12/20/how-to-extjs-stateful-components/#comments</comments>
		<pubDate>Mon, 20 Dec 2010 22:49:05 +0000</pubDate>
		<dc:creator>pAq</dc:creator>
				<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[Ext.Panel]]></category>
		<category><![CDATA[Ext.state.Manager]]></category>
		<category><![CDATA[extjs]]></category>

		<guid isPermaLink="false">http://damian.pcunited.info/?p=12</guid>
		<description><![CDATA[ExtJS allows saving the state of any component that extends Ext.Component. That means that I can store/save, for example in Cookies, state of almost any GUI component made with ExtJS. To store the state of the component so it will look the same after page reload or after going back to the same page I [...]]]></description>
			<content:encoded><![CDATA[<p>ExtJS allows saving the state of any component that extends Ext.Component. That means that I can store/save, for example in Cookies, state of almost any GUI component made with ExtJS.</p>
<p>To store the state of the component so it will look the same after page reload or after going back to the same page I need to do few simple things.</p>
<pre class="brush: js">// 1. Activate a State Manager using State Provider.
// The simplest is the Cookie Provider implemented by ExtJS developers
Ext.state.Manager.setProvider(new Ext.state.CookieProvider());

// 2. Create an Component and mark it as stateful
// eg. GridPanel can save columns order etc.
var grid = new Ext.grid.GridPanel({
   ...
   stateful: true,
   stateId: 'my_grid_id_for_state_manager',
   ...
});</pre>
<p>Now let's try to make a stateful Ext.Panel.<span id="more-12"></span></p>
<p>In ExtJS every Component can be stateful but not all components brought by ExtJS have this behavior implemented.</p>
<p>For example <strong>GridPanel can already store the settings like columns order, sorting direction, columns visibility.</strong> But it can't store for example information if it is collapsed or expanded.</p>
<p><strong>Ext.Panel does not save any information about it's state.</strong> That's why I need to specify what should be stored for example in the cookies.</p>
<p>To do that I just need to specify what should be saved by the State Manager and when.</p>
<pre class="brush: js">// setting up the State Manager
Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
// creating stateful panel that is collapsible and stores it's state - collapsed or expanded
var panel = new Ext.Panel({
// mark it as collapsible
   collapsible: true,

// mark it as stateful
   stateful: true,

// I can specify the Id of the state
   stateId: 'myPanelStateId',

// say what describes the state of the panel - in that case it is the "collapsed" field
   getState: function() {
      return {
         collapsed: this.collapsed
      };
   },

// specify when the state should be saved - in that case after panel was collapsed or expanded
   stateEvents: ['collapse', 'expand']
});</pre>
<p>More detailed information about this topic can be found in the ExtJS documentation - see description for Ext.Panel, especially fields: stateEvents, stateId, stateful.</p>
<p>It should be quit easy to <strong>store the components state in the database</strong>. Thanks to that the user settings related to the ExtJS components could be restored on every machine he is logging in. I "just" need to provide a proper State Provider.</p>
<p>I didn't have a chance to play with it yet. But as soon as I do, I'll write a new post about it.</p>
<div class="twttr_button">
				<a href="http://twitter.com/share?url=http://damiansromek.pl/2010/12/20/how-to-extjs-stateful-components/&text=[How to] ExtJS stateful components - Ext.Panel collapsed/expanded state stored in cookies" target="_blank" title="Click here if you liked this article.">
					<img src="http://damiansromek.pl/wp-content/plugins/twitter-plugin/images/twitt.gif" alt="Twitt" />
				</a>
			</div>]]></content:encoded>
			<wfw:commentRss>http://damiansromek.pl/2010/12/20/how-to-extjs-stateful-components/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

