Custom PHP FastCGI interface? (Faster?)

心已入冬 提交于 2019-12-24 01:53:54

问题


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 :)


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/935202/custom-php-fastcgi-interface-faster

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!