Friday, February 19, 2010

Try to customize the console script in Symfony2

Yesterday, Symfony Reloaded 2.0 Preview was released.
I have tried to use this by symfony-demo.

Symfony 2 is in marked contrast to symfony 1.x, for example, the amount of the directories in Root is only three: "web", "src" and "cart"! How simple!

I found "console" script in the cart directory. when I ran it with the "--shell" option in my console, "Symfony 2" message was displayed like below:

 
So I tried to customize this "Symfony 2" message to change another one.

Symfony 2 is written in PHP 5.3, so each class has "namespace". I copied the files to change from the Symfony 2 core directory and replaced the namespace below:
// namespace Symfony\Framework\WebBundle\Console; // original
namespace Bundle\CartBundle\Console; // new
 and replaced the use path in the console script, too:
//use Symfony\Framework\WebBundle\Console\Application; // original
use Bundle\CartBundle\Console\Application; // new
 I added an ASCII Art, which is the unofficial charactor of symfony that was born in the Japanese symfony comunity and twitter. Her name is "Symfo-Nyan", she is cute!

You can see the original in this page


OK, after adding the ASCII Art to the message, I ran the console again:




  I saw it is easy to customize Symfony 2 but if you are not used to using "namespace" with PHP, you should learn about it.

Tuesday, February 16, 2010

symfony session storage with using MongoDB

MongoDB is  an open source, scalable, high-performance, schema-free, document-oriented database written in the C++ programming language.((via: wikipedia))

symfony has the file session storage class, PDO session storage class but has no MongoDB session storage class.

So I wrote the symfony session storage class with using MongoDB.
You can use below.
http://github.com/brtriver/sfMongoSessionStorage

As a matter of course I don't think MongoDB is the best solution for session storage but it's faster than MySQL session storage.

configuration

If you use sfMongoSessionStorage class, you configure the factories.yml.

storage:
     class: sfMongoSessionStorage
     param:
       host: localhost          #hostname
       port: 27017              #port number
       db_name: symfony         #DB name
       collection_name: session #collection name

bench mark results

This is the bench mark results on my local machine.
$ ab -n 5000 -c 100 http://localhost/index.php

MySQL   => Requests per second:    10.86 [#/sec] (mean)
MongoDB => Requests per second:    16.61 [#/sec] (mean)

Default => Requests per second:    17.58 [#/sec] (mean)
MongoDB session storage is much faster than MySQL one.

I start a new blog in English

My name is Masao Maeda and my online name is brtRiver.
I am a web developer in Japan.
I want to study English and to make friends all over the world.
So I start to write a new blog about the snippets of the web development in English.
Please feel free to follow me "brtriver" on twitter.

Mainly about PHP (symfony, CakePHP and so on..), I'll post :)