This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Friday, October 18, 2013

Complete Framework Components

Besides MVC model-view-controller actually there are more components which built up a complete PHP framework. Let's sum it all:

  • Model is a database representation dealing with tables and other database objects. 
  • View is a visual representation dealing with HTML layouts, CSS, JavaScript, form, buttons, lash messages, etc. This layer also can be extended using tempelate engine/language such as Volt.
  • Controller is responsible for joining model and view together with certain rules and logic.
  • Router and dispatcher is a part of controller which deals with application flow, from one page/process to another.
  • Events Manager is a part of controller which deals with assigning an application event to a specific response.
  • ACL (access control lists) is a part of controller which deals with roles and privileges; who can do what.


Thursday, October 17, 2013

Why I Choose Phalcon PHP Framework

Here's why I choose Phalcon PHP Framework for my project site:
  1. From framework's nature perspective, Phalcon is a C based framework so it's more efficient, faster and lighter than PHP based framework.
  2. From benchmark reports perspective, it has been proven that C based framework is faster and use less resources.
  3. So far there're two option for C based framework; Yaf and Phalcon. I choose Phalcon because it's well documented and they provide a lot samples. 

Wednesday, October 16, 2013

Benchmark Reports on C Based Framework

Because C based framework already running inside the web server, it's obvious that C based framework run faster, and need less resource than PHP based framework. But now we'll take a look several benchmark reports as proofs. This is a simple "Hello World" test, simple MVC logic, no database connections, no complex logic:
Hardware platform
CPU: Intel Core i5 750 (2.67GHz x4)
RAM: 4GB
Software Environment
Debian 6.0.4 x86_64 (2.6.32-41)
apache 2.2.16 (mpm-prefork,mod-php5)
php 5.3.10
php-apc 3.1.9 (Optimization for include/require)
Copy all projects to /dev/shm/* (Optimization for files read/write)
Frameworks list
* zf: Zend Framework
Site: http://framework.zend.com
Ver: 1.11.11
* zf2: Zend Framework
Site: http://framework.zend.com
Site: https://github.com/zendframework/ZendSkeletonApplication
Ver: 2.0.0-beta1
* symfony: symfony
Site: http://www.symfony-project.org
Ver: 2.0.0
* cakephp: CakePHP
Site: http://cakephp.org
Ver: 2.0.4
* ci: CodeIgniter
Site: http://codeigniter.com
Ver: 2.1.0
* yii: Yii Framework
Site: http://www.yiiframework.com
Ver: 1.1.8
* micromvc4: MicroMVC
Site: http://www.micromvc.com
Ver: 4.0.0
* laravel: Laravel, A PHP Framework For Web Artisans
Site: http://laravel.com
Ver: 2.0.2
* slim: Slim Framework
Site: http://www.slimframework.com
Ver: 1.5.0
* yaf: Yet Another Framework in PHP Extension
Site: http://code.google.com/p/yafphp
Ver: 2.1.3-beta (yaf.cache_config=1)
* FuelPHP: Simple, Flexible, Community driven Web Framework
Site: http://fuelphp.com/
Ver: 1.1
* ColaPHP:
Site: http://code.google.com/p/colaphp/
Ver: 1.2-ga
# XHProf: A Hierarchical Profiler for PHP
Site: http://pecl.php.net/xhprof
Ver: 0.9.2
# The source code of this testing:
Source: https://github.com/eryx/php-framework-benchmark
1. Apache Benchmark
Requests pre second (-c 100 -n 30000), the bigger is better
Requests pre second (-c 200 -n 50000), the bigger is better
2. System LoadAvg
System LoadAvg in 1 Minute when Apache Benchmark Complete,
the smaller is better (-c 100 -n 30000)
3. Memory usage
How many memory usage in one "hello world" page. the smaller is better.
4. Response time
The time of page request to response.
5. Number of function calls (Facebook XHProf)
The number of functions calls in one "hello world" page.
The detail of function calls map
Symfony2Zend Framework 1.11.1
Zend Framework 2.0.0-beta1CakePHP 2.0.4
CodeIgniter 2.1.0Yii Framework 1.1.8
Slim 1.5Laravel 2.0.2
MicroMVC 4.0.0Yaf 2.1.3-beta
FuelPHP 1.1ColaPHP 1.2
6. Number of Files
The number of files included or required in one "hello world" page. the smaller is better.
And this is more complex test from various framework.

And another benchmark "Hello World" test, but this time we sent 2000 requests using 10 concurrent connections to each framework.
Framework / Requests per second (#/sec) [more is better]Requests persecondZendLaravelSymfonyFuelYiiKohanaCodeIgniterPhalcon2009001,6002,3003,000
Framework / Time per Request (mean, across all concurrent requests)[less is better]Time perRequestZendLaravelSymfonyFuelYiiKohanaCodeIgniterPhalcon0.20.91.62.33.0
Framework / Number of included PHP files (mean, number on a singlerequest) [less is better]Number ofincluded PHPfilesZendLaravelKohanaFuelYiiCodeIgniterSymfonyPhalcon020406080
Framework / Memory Usage (mean, megabytes per request) [less isbetter]Memory Usage(MB)ZendSymfonyYiiLaravelKohanaCodeIgniterFuelPhalcon0.40.81.21.62.0
From various independent benchmark reports, you can see C based framework (represented by Yaf and Phalcon) has a higher and better results than PHP based framework.


PHP Based Framework VS C Based Framework

Basically there are two kind of PHP framework: PHP based and C based. What is the differences? PHP based framework built by PHP language, which contains PHP files and interpreted simultaneously with your own PHP codes.

In the other hand, C based framework built by C language, which contains C files that already compiled and planted as a web server extension. So the framework is already active in memory together with the web server. These compiled C framework contains classes and methods that can be used and called from your PHP codes.


Because C framework is already active and running in memory, it's faster than PHP framework which still need to reads and interprets files from hard disks. But C framework have downsides, because it's planted as a web server extension, it's a more difficult to maintain than PHP framework. In PHP framework you can change or manipulate the framework without touching web server configuration and service. But in C framework, let's say when you upgrade the framework, you need to recompile and restart the web server.

So wich one is the best? It's totally depends on you and your conditions. If your PHP apps are hosted and you don't have access to web server configuration, then PHP framework is for you. But if you your PHP apps running on VPS or dedicated server, so you have full access to configure the web server, and you need better performance, then C framework is the answer.

Thursday, October 10, 2013

What is MVC?

Model–view–controller (MVC) is a an architecture which separates software development complexity into three layers; model, view and controller. A model is a database representation dealing with tables and other database objects. A view is a visual representation dealing with HTML layouts, CSS, JavaScript, form, buttons, etc. And finally a controller is responsible for joining model and view together with certain rules and logic.


With this architecture, a programmer could modify one layer easily, without worrying thinking whether the modifications could affects other layer significantly. For example, with traditional architecture, when you change the database server, let's say from MySQL to PostgreSQL, then you have to adjust all the queries in your PHP code one by one. Imagine how frustrating and exhausting is this. But thanks to MVC, all you have to do is just change the framework's method which deals with database driver, from MySQL to PostgreSQL. And you don't have to adjust all the queries from your PHP code. Isn't this amazing?

Tuesday, October 8, 2013

Pure PHP Coding VS Framework PHP Coding

As you can see from the picture bellow, a framework simply just an “add-on” which provides methods and toolkits to your original PHP code. So it's easy to understand that this framework add-on will add more bloat to your applications. So why bother coding with PHP framework?


As we have discussed before, when you develop simple applications you mostly don't need a framework. But when your application grow more and more complex, at some point, you need a consistent approach and toolkit which can avoid you from making inefficient code and errors, and helps you build a robust and solid applications.

Sunday, October 6, 2013

Why We Need a PHP Framework?

Why should I use a framework? Why bother learn and code with framework, instead of pure PHP? Because learning and coding with framework invest more time and man power. I asked these questions before I decided to use a framework for my project site.

A framework actually is a code, that contains classes, tools and methods, which you can use to develop a complex application more efficient. When an application grow more and more complex, a conventional approach (pure PHP coding) is no longer efficient and suitable.

If you develop a simple plain PHP site, it's OK to code without framework. In this case, using framework will slow you and your application down. But if you develop a complex and robust PHP site (eg social network), coding without framework is painful and error prone. In this case you need a consistent and efficient approach, which can avoid you for making errors, bugs, or repeating same codes over and over again.