Simon Jia - The Kohana Framework
-
Upload
carolinerose -
Category
Technology
-
view
310 -
download
2
description
Transcript of 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
• Foundation of Kohana Framework
• Setting up Kohana Framework
• How Cracked.com uses Kohana
• Scalability with Kohana Framework
Foundation of Kohana Framework:What makes Kohana a great framework
• Based on HMVC design pattern
• Cascading Filesystem
• Routes
• Validation
• Modules
• Minion
Hierarchical model–view–controller (HMVC)
HMVC has the ability to trigger sub requests to controllers generate specific output.
Cascading Filesystem
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.
Validation: Escape from if..else hell
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
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
Minions – CLI script made simple
With only a few lines of code, a command line script can be created with the Minion module.
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.
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
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
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.
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.
Food! Drinks!Q & A
Simon Jia: [email protected] Kale: [email protected]