views:

236

answers:

2

I was under the impression that FastCGI allowed you to kinda load in your web app once, and then you just "provide" FastCGI with some function, like myHandleHTTPRequest($url), that would then be called whenever a request came. This way you'd get much better performance as your app is ready in memory all the time, right?

But I'm starting to understand, that this is not the case. Or am I mistaken?

It seems to me, that PHP is being loaded by FastCGI, ok, and this gives some improvement, but then my app is still being reloaded on every request.

I'd like to load my app (or read 'framework') once (and then reload say every 500 requests or so.) Can I do that?

Edit: This question has been rephrased into this one: Custom PHP FastCGI interface

+1  A: 

Yeah, you can do that, by more or less forgetting about all of the fancy PHP integration stuff (that being what's giving you General-Purpose-PHP-Interpreter-As-FastCGI) and writing your application as a FastCGI server in and of itself.

That's kind of a whole 'nother topic, but you might want to look into how Perl apps go about it for a guide.

chaos
Ok, thanks! So maybe a better question is: "How do I write a PHP FastCGI server app?"
0scar
I mean, maybe I should post that question here on SO instead...
0scar
A fine idea. :)
chaos
+2  A: 

What fastcgi does is to avoid spawning a php interpreter for every request (like cgi does). This saves huge amounts of processing time, as the php interpreter is kept in memory, more or less like mod_php does.

What you can do to improve performance is:

  1. Use APC, or xcache, etc, which precompiles every php file transparently, avoiding re-compilation on every request.
  2. Caching. Apc and others provide mechanisms to store variables with a lifetime that spans even between requests. This can be used to share processed data between requests, and keep application data in memory.
azkotoki
Thanks! I didn't know about APC keeping data in memory between requests. Cool.
0scar
(Well I didn't know about APC... : )
0scar
I personally see this a more viable option than making a custom interface with fcgi. Making an optional caching system that uses the previously defined mechanisms should be fine. I don't feel that killing portability in favor of integration is a good idea for a framework.
azkotoki