Web @ 13 November 2008, “No Comments”

Regexr - regexp generator

In my experience to-do list one of points are “To know regular expressions better”. But until I can write regexp with my closed eyes, I use very useful resource on web:

RegExr

P.S. Sorry comments does not work. Something changed in new etomite cms. In a future I should migrate to wordpress I assume :)
Update: Wordpres is here ;)

Web @ 21 October 2008, “No Comments”

Sometimes, I need to optimize pieces of code, especially mysql query execution time. But how to check if some piece of code is faster than other?
I use PHP function

Thats how it looks like:

$code_starts = microtime(true);

<some code>

$code_ends = microtime(true);
$execution_time = $code_ends$code_starts;
echo "Done in: ".$execution_time." s";

Have a nice bottleneck finding!

Web @ 25 August 2008, “No Comments”

website speed checker

If your website, blog or portal gets bigger with time, or has/will have huge traffic, you need to find its weakest spots.
This free online tool is very useful, when speach comes to speed. http://tools.pingdom.com/fpt/.

Pingdom tools – a free webtool, which checks your website’s loading speeds. It shows which javascript/image/css loads longest and so on.

MySQL is powerfull enough to make almost anything in web development. Even wikipedia uses it. Of course, I am not guru to understand and make such a big system. But even most of small projects need optimisation. By optimising MySQL queries, you get faster responses from server, smaller database size etc. Size does matter when you use MySQL databases on shared hostings.

There is small article on MySQL optimisation in linuxformat.co.uk wiki

What I did learn from this article:

  • SELECT password FROM users WHERE Username = ‘myuser’ LIMIT 1;

    Always select just fields which you will need in current situation, SELECT * … is not good in most cases. If field by which you filter data, is unique, use LIMIT 1 statement.

  • Create fields with as small data types as it is possible. Good example with age field. It is better to use TINYINT UNSIGNED than INT (who lives negative years and reaches 255 year old? )
  • When database has lots of data, you can check is your schemata is optimised with query:
    SELECT * FROM table PROCEDURE ANALYSE();

    It will show you optimal field data type by analyzing records (look at Optimal_fieldtype column)

  • Add Index to most searchable columns:
    ALTER TABLE tablename ADD INDEX name(column)

    MySQL Index is similar to book’s index.

Web @ 30 October 2007, “No Comments”

If you ever plan to use XML with PHP there is good XMLParser class written by Adam A Flynn. You can get it for PHP4 and PHP5 from his page
http://www.phppal.com/xml/doc.php. There are some examples, so it wont be very hard to understand.

UPDATE: seemes, that www.phppal.com is dead allready :/

You can download the class from my page: XMLParser.zip
To use this class simply copy it in /usr/lib/php directory or if you dont have root permissions, copy in the same folder as your php script.

I had some problems at first, because I was not familiar with data structure after parsing, so I used such code to view, how objects and arrays was formed:

Parse();

//Print all xml children array structure
print_r($parser->document->tagChildren);

That’s all. It is much simplier than i thought to work with XML :)
More info at php documentation: http://lt.php.net/manual/en/ref.xml.php

UPDATE: As PHP5 has much better XML support, you can use now it’s features Read on Zend article