I’ve been banging my head against fastcgi. At a fundamental level, fastcgi is meant to be a CGI gateway allowing multiple simultaneous processes to run at once, to serve pages.
nginx (and Apache, and others) can use fastcgi to run PHP code. Well, Apache can run it “natively” while the others need to run it externally.
Our website is PHP based (drupal).
So are some of our tools. And ya know, the transition to nginx has not been smooth for them. I found that nginx can communicate with fastcgi, and there are many different recipes … and most don’t work (on the net).
So here I am, with a load of PHP code I have to run.
FastCGI is a proxy at the end of the day. It runs php-cgi.
So why again, do I need FastCGI to do what I can do … far better, faster, safer?
Big issue with fastcgi is that the only way you can debug it is via tcpdump or similar packet capture. Why is this good? I want to be able to look at http requests running around. Makes debugging much easier.
Nginx does an absolutely awesome job of proxying. So why not proxy the site I want back to a gateway code that I write to run collections of PHP cgi?
Well … I did it. Less than 1 hour of coding, and the damn thing works, and is quite fast. Even have protection for site stuff in there. Its not generalized right yet. But it will be.
Here’s a snapshot of my desktop with it running:
Basically this was born of my need to run PHP apps, and the inability of me to find a working fastcgi configuration for most of them.
PHP isn’t a great language … its a pretty annoying language in reality. It doens’t have (apart from the now abandoned phpd) the sort of environment like Mojolicious that we can leverage (e.g. no WSGI/PSGI/Plack capability). This makes it very hard to actually develop in IMO.
The windows on the left are the debugger I was running the code in. The window on the right is the test.php window output, which had a simple phpinfo call.
Will do more testing tomorrow. But once I get this fully up, we can hide all our PHP behind Perl application gateways. And more to the point, we can hide pretty much any web code behind these gateways. And we will be adding more robust security, and other elements to the gateway. If PHP could output precompiled byte streams, we could cache these. But I’ve got some pretty crazy ideas for more. Things I can do at (massive) scale with it.
Viewed 54987 times by 5588 viewers