Simon Jia - The Kohana Framework

16
An elegant HMVC PHP5 framework that provides a rich set of components for building web applications. http://kohanaframework.org/ Current Stable Release v3.3.2

description

We'll be talking about the latest version of the Kohana Framework which is built based on HMVC. The talk will cover the following items: - foundation of the Kohana Framework - setting up the Framework and common gotchas - how Cracked.com is currently using it - how Cracked.com scaled based on Kohana Framework

Transcript of Simon Jia - The Kohana Framework

Page 1: Simon Jia - The Kohana Framework

An elegant HMVC PHP5 framework that provides a rich set of components for building web applications.

http://kohanaframework.org/

Current Stable Releasev3.3.2

Page 2: Simon Jia - The Kohana Framework

• Foundation of Kohana Framework

• Setting up Kohana Framework

• How Cracked.com uses Kohana

• Scalability with Kohana Framework

Page 3: Simon Jia - The Kohana Framework

Foundation of Kohana Framework:What makes Kohana a great framework

• Based on HMVC design pattern

• Cascading Filesystem

• Routes

• Validation

• Modules

• Minion

Page 4: Simon Jia - The Kohana Framework

Hierarchical model–view–controller (HMVC)

HMVC has the ability to trigger sub requests to controllers generate specific output.

Page 5: Simon Jia - The Kohana Framework

Cascading Filesystem

Page 6: Simon Jia - The Kohana Framework

Routes

Kohana Routing

• Provides easy way to direct requests to specific controllers• Supports regex pattern matching• Sub patterns on Routes can also be made optional making Routes more

dynamic

Tips & Gotchas

• Routes are matched in the order they are added similar to how .htaccess rewrite rules work.

• Catch-all routes should be placed at the last position.• Routes can be defined in “init.php” of each module.

Page 7: Simon Jia - The Kohana Framework

Validation: Escape from if..else hell

Page 8: Simon Jia - The Kohana Framework

Modules

Out of the box, Kohana ships a bunch of optional but very useful modules.

- Authentication: simple login/logout user authentication- Cache: a common interface for caching engines- Codebench: powerful benchmark tool- Database- Image: powerful image manipulation module- Minion: banana…..- ORM: love it or hate it- Unittest

Page 9: Simon Jia - The Kohana Framework

Modules

The Kohana Module system is designed to make modules portable.

It can be designed at any level in the Cascading Filesystem. In fact, all Kohana native features and components are built as modules.

Cracked.com’s code base currently share multiple modules with other properties at Demand Media.

The process of importing module consists of three steps:1. Copy2. Paste3. Add definition to bootstrap.php

Page 10: Simon Jia - The Kohana Framework

Minions – CLI script made simple

With only a few lines of code, a command line script can be created with the Minion module.

Page 11: Simon Jia - The Kohana Framework

Setting up Kohana

Upload Kohana to your server, and browse to http://<yourdomain>/<path to kohana> Follow the instructions and install any missing PHP modules and you are good to go.

Page 12: Simon Jia - The Kohana Framework

Cracked.com

• #1 Comedy Site in US per Comscore 03/2014

• 15 Million Daily Page Views

• 11 Million Monthly Unique Visitors

• Built on LAMP + Kohana + Redis

• Heavy Read/Write Volume

Page 13: Simon Jia - The Kohana Framework

How Cracked uses Kohana

- Application, Module, System are moved out of the public accessing folder

- Third-party modules, including Kohana’s default modules are kept in vmodules folder

- Each section of the site is kept in its own module

- Base classes are kept in Application

- Any extension or wrapper classes to Kohana’s system level classes are kept in Application

Page 14: Simon Jia - The Kohana Framework

Scalability of Kohana Framework

Cascading Filesystem is awesome, but very taxing on high traffic sites. Pre-caching the file lookups as part of the production release script will dramatically increase the performance.

Page 15: Simon Jia - The Kohana Framework

General Scalability of, well Kohana and LAMP

• Use opcode caching (APC) to cache compiled PHP scripts

• Use cache, but don’t over do it. Too many small cache calls within a request can create a bottle neck. If using Redis, make use of the mGet()

• Profile your code before production Release. Kohana provides a out of box Benchmark tool which works fairly well. (Benchmark::start() + Benchmark::stop())

• Remove any unused modules in Kohana or take it out of bootstrap.php. This will reduce the Cascading Filesystem lookups.

• Minify and mash your javascripts and css files.

Page 16: Simon Jia - The Kohana Framework

Food! Drinks!Q & A

Simon Jia: [email protected] Kale: [email protected]