How do you build your own FastCGI interface in PHP?
I'd like to do something similar to what they're doing in Perl, but in PHP. Is it even possible? Would it be faster?
(That is, I'd like to be able to load a web app framework once into memory, and then just have FastCGI call a method I provide for every request. So not the more generic preloading of the PHP-interpreter that is happening in the "default" PHP FastCGI setup.)
cheers!
(Edit: Isn't Mongrel and RoR doing this as well?)
Ok I've made a freakin' diagram now :)
I may be mistaken (it's late) but aren't you just trying to do some form of caching? Regardless, the FastCGI interface seems to be fairly well defined. So, it should be possible to do whatever you want, fairly easily.
You can not do it in PHP for PHP, you can do it in C for cgi-sapi but you probably want to use APC instead.
If you are really determined for it to be in PHP, you could in theory, create a php module in c, and form the bridge for fastCGI in c.
After which im guessing, you would run a PHP script accessing fastCGI as a standalone program, running a loop and accepting requests. In which your using PHP as a "persistent virtual machine" (could not find a better term), that communicates via fastCGI.
I do agree that the reloading of several of your dependency libaries / etc, is a very easily over-sighted performance drain. However, it maybe intentional design, in simplifying the PHP development cycle. Think of the global variable mess inexperienced users would make, in a persistent environment. Toss in the fact that most fastCGI setup, will initialize multiple copies / threads according to the load. Its a small can of worms. Starting a blank new slate for each request simplifies it.
However, honestly... if your that concern in performance, you might as well consider fastCGI C++ / node.js, as alternatives.... Having developed for JavaScript/PHP/C++, your idea is definitely possible... However it really boils down to cost-benefit... Is it worth the effort?, etc.
PS : You can also consider compiling your PHP sites via hip-hop.