

Silex: ExpressJS for PHP - bergie
http://bergie.iki.fi/blog/silex_is_like_expressjs_for_php/

======
morganpyne
Since I follow most of the mailing lists for Symfony 2, I have come across
Silex a little while ago. However, something new I took from this article was
the appserver-in-php project <https://github.com/indeyets/appserver-in-php>

The blurb on the git project has "The main idea is, that your app, if built
for this protocol, will be able to preload resources, preconnect to databases
and response to requests really fast.", which seems like it's taking a
persistent approach to running PHP apps. How does this deal with the memory
leaks etc?

Can anybody knowledgeable weigh in on this with a little detail about what it
is, how stable it is, who's using it, how it stacks up to using PHP-FPM in a
spawner pool w/ nginx etc... ?

~~~
bergie
I'm the author of the original post. We use AiP quite a bit in production.

Indeed, memory leaks are a potential issue with persistent PHP. Garbage
collection in 5.3 helps a bit, but in general AiP exposes such issues more
readily than regular mod_php setups. This doesn't mean memory leaks in your
code wouldn't be an issue anyway, it just means you'll notice them a lot more
quickly.

AiP workers die when PHP's memory_limit is exceeeded, and AiP will then
restart them.

~~~
morganpyne
Thank you for your reply. I will have a play with it if I find some free time.
It's not the memory leaks in _my_ code I'm so worried about, it's the ones in
other people's code :-) e.g. Doctrine used to leak like a sieve and no amount
of free()s and unset()s cleared the ORM objects up under some circumstances.
Long-running Symfony tasks were a great way to illustrate that. It seems like
a sensible approach to auto-restart the processes once memory_limit is
exceeded.

~~~
bergie
During one minute of siege to the "hello world" example from my blog post, the
memory usage of my PHP processes didn't change.

    
    
      13958 bergie    20   0  125m  10m 2136 S    1  0.6   0:00.28 php        
      13959 bergie    20   0  125m  10m 2136 S    1  0.6   0:00.31 php

~~~
morganpyne
While I'm relieved to see that, I wouldn't expect anything less from a trivial
example such as this. I wonder if the same would be true if you hit a
database, hydrated a one-to-many related series of objects from multiple
tables using an ORM, modified some of them and save them etc.

However, I don't mean to harp on about the memory leaks; It's just that it
seems to have been an assumed wisdom in my long association with PHP that
you're going to need to restart PHP processes eventually. Perhaps the GC in
5.3 alleviates some of these concerns (including detection of circular
references), as does the maturing of the code base and the commonly used
libraries over the years.

The fact that you are using AiP happily in production already means that there
is both a niche and a successful way to implement this so I'm glad to see new
approaches like this emerging.

~~~
indeyets
Hi. I am the author or AiP.

There were a lot of leaks, when I tried this idea originally, back in php 5.2
days. See [http://blog.milkfarmsoft.com/2007/06/php-as-appserver-vs-
mem...](http://blog.milkfarmsoft.com/2007/06/php-as-appserver-vs-memory-
leaks/) for example.

But 5.3 solved all of the issues. The only leaks happening these days come
from "unofficial" extensions, which introduce errors on C-level. PHP code
_never_ results in memory leaks these days, as far as I know.

------
s3u
Any reason your tests used HTTP/1.0? It is likely that most of the time is
spent in connection establishment and you may not have tested the server.

------
chrisohara
how is this anything like express?

See klein (<https://github.com/chriso/klein.php>) for a real PHP express
port..

~~~
bergie
All of them are inspired by Sinatra. But does Klein do templating, like Silex
and ExpressJS both can?

