PHP Framework – Siapa yang tercepat?
![]()
Kali ini saya membandingkan enam PHP Framework berbasis MVC (Model View Controller) yang populer. Keenam framework itu adalah CakePHP, CodeIgniter, Kohana v2 dan v3, Yii, dan “new kid on the block” DooPHP. Semua menggunakan versi terbaru saat ini (2009-11-22) kecuali Yii. Berikut informasi detail mengenai versi yang di-test:
- Cake PHP 1.2.5
- Code Igniter 1.7.2
- Kohana 2.3.4
- Kohana 3.0.1.2
- Yii 1.0.10
- Doo 1.2
Mesin yang digunakan
Acer Aspire 4520
AMD Turion 64 X2 TL-58 1.9 GHz
RAM 3 GiB
Software yang digunakan
- Windows 7 Ultimate
- Apache 2.2.12
- PHP 5.3
Hampir semua framework konfigurasi-nya tidak diubah sama sekali (kondisi default). Kecuali Cake PHP yang sudah dimatikan konfigurasi session, cache, database, log, dan debug.
Metode test yang digunakan mencetak tulisan “Hello World!” lalu langsung exit;.
Hasil yang didapat adalah nilai rata-rata dalam satuan rps (request per second). Berikut dari yang terlambat hingga yang tercepat:
- CakePHP ==> 19.72 rps
- CodeIgniter ==> 71.23 rps
- Yii ==> 73.68 rps
- Kohana v2 ==> 76.31 rps
- Kohana v3 ==> 103.39 rps
- Doo ==> 200.32 rps
Terlihat Doo buatan negri tetangga adalah yang tercepat dalam test “Hello World!” ini.
Tapi dalam memilih suatu framework, bukan mana yang tercepat. Tapi yang paling nyaman anda gunakan sehingga mempersingkat waktu developing dan meningkatkan produktivitas anda.
Berikutnya akan ada tambahan dari PHP Framework berbasis MVC lainnya seperti Symfony, Zend Framework, dan APF, Solar Framework. Dan agar lebih fair, semua session, cache, database, dll akan di-non aktifkan. “Hello World!” juga akan dicetak pada view, bukan pada controller lalu exit.
Nb: Konfigurasi module dan extension yang sedang berjalan pada Apache dan PHP tidak diikutsertakan dalam tulisan ini.
Membuat RSS Feeds
Tambahkan pada <head>
<head> <link rel="alternate" type="application/rss+xml" href="http://url-php-anda/rss.php" /> </head>
Struktur XML
</channel>
<?xml version="1.0" ?> <rss version="2.0"> <channel> <title>Judul Pertama</title> <link>http://www.url-anda.com/page/1</link> <description>Hallo ini ada lah judul pertama hehehe..</description> </channel> <channel> <title>Judul kedua</title> <link>http://www.url-anda.com/page/2</link> <description>Kalo yang ini yang kedua</description> </channel> </rss>
Kalau ada gambar, tambahkan didalam <channel>
<image> <url>http://www.url-anda.com/hola.gif</url> <link>http://www.url-anda.com/page/1</link> </image>
Ini tutorial bikin blog simple pake Kohana
Diambil dari kohana-id@googlegroups.com
Blog nya ini simple banget.. cuma CR… bukan CRUD…
Semoga bisa sedikit membantu buat yang baru belajar Kohana..
Isi file application/controllers/welcome.php
<?php
class Welcome_Controller extends Template_Controller {
public $template = 'template'; // View yang terdapat pada 'views/template.php'
public function __construct() {
parent::__construct();
$this->template->menus = array('Home'=>'welcome',
'Article'=>'welcome/article',
'Post'=>'welcome/post');
}
public function index() {
$this->template->content = 'Ini Home';
}
public function article () {
$this->template->content = new View ('article');
$db = ORM::factory('article'); $data = $db->orderby('sent','DESC')->find_all();
$this->template->content->isi = $data;
}
public function post () {
$this->template->content = new View ('post');
}
public function save () {
$db = ORM::factory('article');
$db->subject = $_POST['subject'];
$db->message = $_POST['message'];
$db->sent = date('Y-m-d H:i:s');
$db->save();
url::redirect('welcome/article');
}
}
Isi file application/views/template.php
<html>
<head>
<title>Simple Blog with Kohana</title>
<style>
body {
background: black;
color: #fff;
font-family: Arial, sans-serif;
font-size: 14px;
}
a, a:visited {
color: orange;
text-decoration: none;
}
a:hover {
color: gold;
}
#wrapper {
width: 760px;
margin: auto;
}
input, textarea {
display: block;
}
.sent {
color: #333;
}
#menu li {
margin-right: 10px;
display: inline;
}
.float-left {
float: left;
}
.float-right {
float: right;
}
.clear {
clear: both;
}
.center {
text-align: center;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="header"><h1>Simple Blog with Kohana</h1></div>
<ul id="menu">
<?php foreach ( $menus as $menu => $url ): ?>
<li><?php echo html::anchor($url, $menu) ?></li>
<?php endforeach ?>
</ul>
<div id="content"><?php echo $content ?></div>
<div id="footer">Copyright© 2009 mul14</div>
</div>
</body>
</html>
Isi file application/views/article.php
<?php foreach ($isi as $v): ?> <h2><?php echo $v->subject ?></h2> <div>Sent: <?php echo $v->sent ?></div> <div><?php echo $v->message ?></div> <?php endforeach ?>
Isi file application/views/post.php
<?php
echo form::open('welcome/save');
echo form::label('subject', 'Subject') . form::input('subject');
echo form::label('message', 'Message') . form::textarea('message');
echo form::submit('send', 'Send');
echo form::close();
?>
Isi file application/models/article.php
<?php
class Article_Model extends ORM {}
MySQL nya:
CREATE TABLE IF NOT EXISTS `articles` ( `id` int(11) NOT NULL AUTO_INCREMENT, `subject` tinytext CHARACTER SET utf8 NOT NULL, `message` text CHARACTER SET utf8 NOT NULL, `sent` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ; INSERT INTO `articles` (`id`, `subject`, `message`, `sent`) VALUES (1, 'Vestibulum hendrerit', '<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas nisi. Praesent pharetra augue quis magna. Nulla eros. Donec quis urna in lorem nonummy iaculis. Suspendisse tempor venenatis mauris. Cras pulvinar purus id leo posuere imperdiet. Duis aliquam elementum ipsum. Proin non leo. Aliquam erat volutpat. Etiam ultricies pede eget nulla.</p>\r\n', '2009-06-28 03:15:16');
Jangan lupa sesuaikan isi application/config/config.php
PHP Output Buffer
Ini Tips buat para newbies yang jengkel kalo pake session ato header() sering muncul tulisan Warning: Cannot modify header information – headers already sent by….
Gunakan fungsi output buffer di php.
<?php
echo "Lembu";
session_start();
?>
Biasanya contoh diatas akan muncul error message: Warning: Cannot modify header information – headers already sent by….
Sekarang coba gunakan ini:
<?php
ob_start();
echo "Lembu";
session_start();
ob_end_flush();
?>
Masalah terpecahkan..
Get Screenshot with PHP
Kemarin abis download PHP Manual yang baru. Lalu aku isenk baca PHP Manual: Migrating from PHP 5.1.x to PHP 5.2.x. Ternyata cukup banyak juga perubahan. Dan beberapa ada yang tidak compatible dengan versi sebelum-nya.
Tapi dua function baru yang menurut saya sangat menarik. Yaitu imagegrabscreen() dan imagegrabwindow(). Kedua function ini ada mulai PHP versi 5.2.2.
Sekarang dengan, anda bisa mengambil screenshot user server. Caranya:
<?php $im = imagegrabscreen(); imagepng($im, "myscreenshot.png"); ?>
Sayangnya kedua function ini ada bekerja pada platform Windows. Semoga nantinya juga bisa bekerja di platform Unix/Linux, mengingat Unix/Linux banyak digunakan pada server.
—
Ralat, ternyata function ini bekerja di server-side. Jadi gambar yang diambil hanya gambar yang sedang dibuka di server.