best cricut
May
13
2009
--

Yii Framework controller and view path convention

Yii Framework has just upgraded to 1.0.5, really glad that Qiang could keep up the momentum to release an update every month. We strongly believe with this level of activity, this open source project will soon becoming the most popular and comprehensive PHP framework. However the only problem this brings is the question "To upgrade or NOT to upgrade?". For a real life project, it's bit hard to keep up with the monthly upgrade, especially when things are constantly changing and improving. Some upgrade really brings the benefit of stability and versatility to the framework, but there are bad times...

Yesterday as usual, we have upgraded our Yii version to 1.0.5, and one of the project we are working on suddenly stopped working almost completely. That was because of a little change in the view path naming convention. To read more about the issue please refer to Issue 307.

To avoid this, please keep this naming convention in mind:

  • Name controller ID in lowercase only with the very first letter/word capitalized.
  • If a controller ID has multiple words try to separate them using underscore '_' or hyphen '-' to concatenate them, NOT capitalize any following words
  • All view path/directory should be all in lowercase and with underscore '_' or hyphen '-' for concatenation.
This directory naming convention should prevent any problem on both Windows or *nix platform.

The only last thing we didn't really agree with Qiang is that a controller would only be accessible by only one URL, not both capitalized or lowercased word(s), simply because an URL should be unified and universal. We would like to leave this discussion to all the Yii enthusiast.

Feb
06
2009
5

mwbModelCommand, Yii Framework and MySQL Workbench

In the past few weeks we have been exploring with Yii Framework, and two of us have started porting some of our project to Yii Framework. One of the first few things that caught our attention is the CActiveRecord model classes, which require relational rules to describe relationships among database tables. We are glad that Yiic can help to create project scaffolds and create controller, model and CRUD, however it's not very practical to manually add all the relationship if your project has over 10 tables.

Our normal practice prefers to design database with relational diagram, so it not only sets out the table schemas but also visually demonstrates the relationship of database tables. However in this fast changing world, without the right tool most the relational diagram tends to out of sync with real production database. For most the of our project, we create ERD and generate database from the diagram in the design phase and later on in the development phase, most the developer choose to update the schema on the table directly, since that's quick, and most of them don't have the habit to update the ERD with relavant changes. You will feel lucky if your database design tool comes with reverse engineering, which can help you syn with your database at a later point still, otherwise you'll be purely rely on your bare eye and hand to syn among database table your model classes and the ERD.

So I believe when it comes to database design it should always be diagram driven, therefore if there's any changes need to be made, always update the digram first and carry on to your physical table and model class. Although we are still looking for good database migration tools to manage schema diffs. We have written a little script to help Yii Framework to work with MySQL Workbench (which we use to model MySQL databases), the purpose of the script is to batch create model classes for Yii Framework (although Yiic can generate models one by one, we want it happen at once and for all), and with the help of mwb file it can create the relational rules for the models, so there's no manual translation needed while you creating the models. Since it's a Yii shell command, we have named it 'mwbModelCommand'.

It's available for download at this Yii Extensions page, or Yii Framework mwbModelCommand (direct link)

Hope this script will save your time on relational model creation, if anyone have issues or suggestions mwbModelCommand please feel free to post back.

Wish List (Todo),
A tool (set) to stream line the database migration, so it would not only creates the models, but may also update (revert) models as well as database table schema at once, and data safe if possible. Please advice if you know something good out there.

Jan
17
2009
10

PHP Frameworks Comparison Test

We have done enough reading and digging on the net just to see how others test and compare PHP frameworks, however there are hardly anything recent and convincing. Most of the test are on throughput of a simple 'Hello World' page, which we don't think reflect the real performance of a framework, simply because no Database interaction was involved, hence Model as in MVC is not tested at all. So we decide to conduct our own test with a more real world case, which would require MVC work together intensively to get up the result.

The Test

We have each programmer picked a popular PHP framework, and the task is to setup the framework and create MVC for the benchmark, which involves,
  • 1000 database insertion
  • 1000 database update
  • query 1000 records (all fields), and display in a list
  • each record size is about 2kb
We then put all the coded project onto one work station which has the following configuration,
  • Pentium 4, 4.3GHz
  • 2GB RAM
  • Windows XP, SP3
  • XAMPP 1.7.0 (patched to work with PDO)
  • APC enabled (Zend Optimizer disabled)
  • All programs turned off, including Anti-Virus and Firewall
We use a PHP batch script under CMD to make queries to each framework 10 times, and reports on the average response time and memory usage.

The Result

Framework Database Engine Avg. Response Time Avg. Memory Usage
Pure PHP mysqli 5.28s
 
0.14MB
 
oModel* adodb mysql 7.13s
 
6.88MB
 
Yii Framework
(yiilite)
pdo_mysql 7.41s
 
8.38MB
 
Yii Framework pdo_mysql 7.7s
 
9.44MB
 
Kohana mysqli 7.68s
 
11.22MB#
 
Zend Framework pdo_mysql 8.37s
 
7.99MB
 
Zend Framework mysqli 11.28s
 
7.88MB
 
Akelos mysqli 12.98s
 
10.93MB
 
* The Orite in-house lightweight MVC framework
# With <benchmark> parameter turned off in the database config file, it only uses 1.5MB memory, and takes about 7.8s. Thanks Jeremy Bush for the advice. (updated 24/07/2009)

The Verdicts

Framework Pro. Con.
oModel Fastest framework, light file structure, highly flexible, real short learning curve Not as comprehensive, not well documented, no community support, need high skill set to work on for large-scale project
Yii Framework Fast, comprehensive, simple and secure file structure, strictly php5 OO, well documented, code generation Farely new, still building community awareness
Kohana Flexibility, Easy start Big memory footprint, DB feature incomplete
Zend Framework Great library set, flexible, best community support Long learning curve, code generation problem*
Akelos Great RoR port, database migration Slow, php4
* We have try to run Zend-Tool on two workstations, all failed to run

The Conclusion

We understand this benchmark comparison is still bit off the real world, as it has too much emphasis on the database operation, where as in real web scenario the result can vary on different server deployment. Also, we didn't test cache mechanisms under each framework, which would play a real important role in the production environment, when server gets lot of hits on dynamic content, the result can be really different depend on project nature. Hopefully Orite will further test  real web project taken most the core features of frameworks in consideration. If we were after speed, we would stick with oModel which had been the backbone of lots of recent Orite projects. After testing the frameworks, our team had picked both Zend Framework which has the most supportive community and feature set, and Yii Framework the good combination of comprehensive feature, ease of use and performance. We will start few project based on Yii Framework and continuously keep eyes and hands on Zend. Interesting findings regarding this topic will be posted after we have dived into these frameworks a bit more.

Copyright Orite Group Pty Ltd | Powered by WordPress | Theme: Aeros 2.0

https://www.runthemusic.com/