Photon could save PHP

(written by lawrence krubner, however indented passages are often quotes). You can contact lawrence at: lawrence@krubner.com

I have been extremely critical of PHP for the last 2 years. See “Why PHP is obsolete“. However, I just stumbled across Photon, which seems to address some of the core problems I see with PHP (especially the lack of any tools for dealing with concurrency):

Why targeting Mongrel2?

Mongrel2 is a very well designed, high performance server developed by pragmatic users who do not like bloated software. The use of ZeroMQ as the communication hub makes it extremely flexible while keeping the incredible performance. As a result, one can easily write part of a project with Photon and use other languages for some special parts. Oh, and the community behind Mongrel2 is really nice.

What is the interest of ZeroMQ?

ZeroMQ is a high performance messaging layer on top of TCP, IPC or PGM multicast. With ZeroMQ, you can easily get a worker to connect to the Mongrel2 server over your LAN, this makes extremely easy to distribute your workers on several systems with zero configuration. For example, you can migrate your workers from one host to another without downtime.

# Start Photon on server 1, all the load is handled by server1
you@server1:~/myproject$ hnu server start

# Start Photon on server 2
you@server2:~/myproject$ hnu server start

# Now the requests are spread over server1 and server 2
# Stop Photon on the first server
you@server1:~/myproject$ hnu server stop

# All the load is handled by server 2 without any downtime
# and no reconfiguration of Mongrel2.

Of course you can distribute the load over your workers with more than just a round robin pattern.

Why not just a Mongrel2 adapter for an existing framework?

To really take benefit of Mongrel2 one needs to have an asynchronous framework. With Mongrel2 you do not have the traditional one request get one answer approach. This means that the standard PHP SAPI, which needs for each request an answer, is not adapted. As all the current frameworks are using the one request, one answer approach, you cannot take full benefits of Mongrel2 with them. For example, you cannot easily create an MP3 streamer or a realtime chat application.

Source