Difference between #15 and #19 of
Performance - A Guide For Best Practice

Changes

Title changed

Performance - A Guide For Best Practisce

Category unchanged

Tutorials

Yii version unchanged

Tags changed

performance

Content changed

In this guide I will explain best practise regarding performance in MySQL, PHP and of course our loved Yii Framework. Since this is a complex topic, I will start with some basics and then expand this guide from time to time. Since this cookbookwiki can become big, you may click on `RevisionView history` - there you can see what changes have been made, so you don't miss anything. Also note that one may find some topics unnecessary because the performance gain is minimal. Still I think it's good to list those topics, even if it's only for a better insight. >Info: I urge other authors not to edit this cookbookwiki, but of course anyone can make suggestions in the comments section or drop me a private message in forum. Thanks! # Table Of Contents #
 
 
- __`1. MySQL`__
 
   - `Setting The Best Suited Charset`
 
   - `Working With IP Addresses`
 
- __`2. PHP`__
 
   - `The Type-Safe Operator`
 
- __`3. Yii Framework / Applications`__
 
## 1. MySQL ## >Info: Some overview description soon... ### Setting The Best Suited Charset ###

When working with UTF-8 charsets (or multibyte charsets in general), it's good practise to set the proper collation charset for each database table.
[...]
A real performance boost will show up with a lot of entries in a table. Still there's no argument not to do it for small tables also.

##
# Working With IP Addresses ### Most PHP applications I've seen save ip addresses as a `string` of column type `VARCHAR(15)`. This works well and is already fast when used with an index. Still there is a much better solution. PHP has the function [`ip2long()`](http://php.net/manual/en/function.ip2long.php) which converts an ip address into a numerical value. The ip address `127.0.0.1` of type `string` would be converted into `2130706433` of type `integer`. The function to do the conversion vice-versa is called [`long2ip()`](http://php.net/manual/en/function.ip2long2ip.php). In MySQL these two functions are called [`INET_ATON()`](http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function_inet-aton) and [`INET_NTOA()`](http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function_inet-ntoa).

The type of the column for such a numerical ip address must be `INT(10) UNSIGNED`.
[...]
So when saving ip addresses as numerical values, you have the benefit of faster selections/sorting and the size of the table will be smaller since `INT(10)` consumes 4 bytes whereas `VARCHAR(15)` consumes at least 16 bytes or more (depends on the used charset).

Not
e that this only works with ipv4 addresses. ## 2. PHP ## >Info: Some overview description soon... ### The Type-Safe Operator ###

PHP has a loose typing system. That means when comparing values, each value can be of a different type.
[...]
As you can see it's quite simple. If you use the type-safe operator extensively, you will have a small performance boost and your statements will be less error-prone since you always compare values of the same type. Also note that using the type-safe operator is always faster, even if you cast each value you want to compare to a specific type.

## 3. Yii Framework / Applications ## >Info: Soon
9 5
10 followers
Viewed: 27 891 times
Version: 1.1
Category: Tutorials
Written by: Y!!
Last updated by: ajsharma
Created on: Feb 4, 2010
Last updated: 13 years ago
Update Article

Revisions

View all history