librelist archives

« back to archive

Fwd: Photon, PHP framework for Mongrel2

Fwd: Photon, PHP framework for Mongrel2

From:
Loic d'Anterroches
Date:
2011-01-18 @ 07:35
Announce done on the Mongrel2 mailing list.

-------- Original Message --------
Subject: Photon, PHP framework for Mongrel2
Date: Mon, 17 Jan 2011 21:57:46 +0100
From: Loic d'Anterroches <loic@ceondo.com>
Organization: Ceondo Ltd
To: mongrel2@librelist.com

Hello,

short, if you just happen not to like PHP, just skip, if you are
curious, just go ahead.

So, I created a small framework for Mongrel2 in PHP. What you get is
basically an application server in PHP which is single process, single
thread. It scales by starting more processes. And it is:

- fast.
- a long term PHP process, so no need for a bytcode cache.
- on memory diet with 2MB of memory per process (when not handling a
request).
- robust, you can pour in a 200MB POST request and it will magically
swap it and only parse on demand the POST fields.
- easy to control from the command line (using a zmq control socket).
- automatically sign your cookies to trust them for message passing
(sha1 hmac).
- does not require a database.

Example of usage:

$ photon init myproject
$ cd myproject
$ photon server start
$ curl http://localhost:6767/handlertest/foo
Hello World!
$ photon server list
Waiting for the answers...
Photon id                     Uptime        Served  Mem. (kB)  Peak mem.
(kB)
-------------------------------------------------------------------------------
loa-desktop-29874-1295296119  0d00:00:40    1       1517       1928
-------------------------------------------------------------------------------
1 Photon servers running. Memory usage: 1517kB.
$ photon server start
$ photon server listWaiting for the answers...
Photon id                     Uptime        Served  Mem. (kB)  Peak mem.
(kB)
-------------------------------------------------------------------------------
loa-desktop-29874-1295296119  0d00:01:24    1       1517       1928
loa-desktop-29896-1295296185  0d00:00:18    0       1352       1362
-------------------------------------------------------------------------------
2 Photon servers running. Memory usage: 2870kB.
$ photon server stop
Waiting for the answers...
Photon id                     Answer
---------------------------------------
loa-desktop-29896-1295296185  KO
loa-desktop-29874-1295296119  KO
---------------------------------------
2 Photon servers stopped.

Source: http://projects.ceondo.com/p/photon/
List:   photon.users@librelist.com

# Some Q/A

When announced on my blog, I have received a bit of heat, here are some
of the questions and answers.

1. Why PHP?
The interest of using PHP is that, basically, PHP is just a glue code
over C libraries. This is why it is really really fast.

2. Why another framework in PHP?
All the current frameworks are designed to work with one request/one
answer model. You can get the request from Mongrel2 and inform a python
server through zmq to send the answer. I wanted something with minimal
memory foot print too.

3. PHP sucks at memory management, long running processes with PHP is a
dead end.
PHP as fastcgi already restarts each child after 500 requests, the PHP
interpreter is extremely fast to start, just get your Photon processes
to die after n +/- rand(n/10) requests and be restarted by your process
manager. You can also let them die if a memory threshold is reached
after the processing of a request.

4. For which usage?
For the fun of playing with Mongrel2 and zeromq, but especially for
Cheméo. Cheméo is a chemical property search engine and model
devolpment. Models are regressed using Python + R, so it will be
possible to have some small services powered with zeromq and get Photon
to communicate with them. http://www.chemeo.com

The doc folder is still just a brain dump, not up-to-date, the code is
early alpha code. But for people interested in PHP+Mongrel2, you can
have some fun.

Source: http://projects.ceondo.com/p/photon/
List:   photon.users@librelist.com

loïc

--
Cheméo, High Quality Chemical Properties - http://www.chemeo.com
Indefero - Project management and code hosting - http://www.indefero.net
Céondo Ltd - Web + Science = Fun - http://www.ceondo.com