The way I see it Website development (PHP, JS, MySQL) by Damian Sromek

31Mar/120

[How to] Speed up Windows 7 boot-up time – turn off media sharing

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 it should.

After checking in "Performance Monitor" (standard Windows tool) I've noticed that Wmpnetwk.exe process is performing most of the HDD I/O operations.
This is part of the Windows Media Player which lets you share media through network. @see Windows media sharing

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.

How to disable Windows media sharing?

  1. Run services.msc
  2. Stop and disable  "Windows Media Player Network Sharing" service

You can read this post for more details (screenshots).

21Mar/120

[Presentation] Thin controllers – fat models.

5Nov/110

PHPCon PL 2011 – Safety of web applications (Przemysław Pawliczuk)

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 "<?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 has been hacked.
  • Let people in your company use the app for the first time to play and try to break it.
  • Separate development from production machines on every aspect.
Tagged as: , No Comments
4Nov/110

PHPCon PL 2011 – how to increase productivity of PHP programmer (Adam Puza)

AutoHotkeyYou 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 one place, eg. Keypass
  • Use shortcut keys, eg. with AutoHotkey
  • Learn IDE shortcut keys. Search files using keyboard, not mouse.
  • Use virtual machines when you have to set up specialized environment to work with some project.

What's the best way to learn shortcut keys?

  1. Do something using mouse.
  2. Next check how can it be done with just a keyboard.
  3. Revert action and do it using a keyboard.

You can read more interesting things out of his presentation.

26Oct/110

PHPCon PL 2011 – Yii Framework – just another MVC or maybe small revolution? (Krzysztof Maziarz)

Yii logo
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 at it a bit but I was not convinced it's so much better than the other frameworks.
After that presentation I've decided to take a bit closer look. That's what I think about it.

24Oct/110

PHPCon PL 2011 – Geolocation and Maps with PHP (Derick Rethans)

OpenStreetMap logo
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.

Almost all developers think about Google Maps when they consider solutions that will let them use maps on a site they are building.
But as Derick showed us there are alternatives for Google Maps.
He has mentioned Leaflet (JavaScript library for interactive maps) and OpenStreetMaps (open alternative for Google Maps).

You can see his presentation here. 

According to Derick you can even host your own map service thanks to OpenStreetMaps data that can be downloaded for free.
His presentation was full of "realtime demos" what made it really interesting.

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.
With a bit of imagination and creativity you can create amazing and interesting things.
I can't wait to play with that some day.

3Jan/119

[How to] Run PHPUnit tests using database 10x faster

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 work - License Statistics - uses quite a lot of unit tests.
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.

Right now we have something around 1 000 tests that check around 3 000 assertions. Much of them involve database operations. That's why running all tests on Windows machine can take up to 25 minutes.

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.

3Jan/110

[Watch out] Zend_Date performance

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 run a profiler for one of the pages I created and I saw huge impact on the performance that Zend_Date had.

It did speed up development and made it easier but it also made the code much slower. Zend_Date Comparing with the plain PHP DateTime was like 5 to 10 times slower. Even Zend_Date::toString took quite large amount of CPU time.

Solution - use PHP DateTime instead of Zend_Date

Solution for that part of code was replacing the Zend_Date used in the loops (executed even couple hundred times) with DateTime. 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 DateInterval into DateTime::add().

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.

Some of DateTime features are available since PHP > 5.3 but you can easily use DateTime with older PHP doing small changes in the code.

21Dec/100

[Watch out] Doctrine_Query::fetchOne()

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 it's not quite true because it returns one row, but at the back-end it fetches the whole collection.

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.

Solution

Simple solution for that is to specify limit by hand, before executing fetchOne().

/* @var $query Doctrine_Query */
$query->limit(1);
$record = $query->fetchOne();
20Dec/100

[How to] ExtJS stateful components – Ext.Panel collapsed/expanded state stored in cookies

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 need to do few simple things.

// 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',
   ...
});

Now let's try to make a stateful Ext.Panel.