I always used Apache for my PHP projects. But now, I want to leave it, to start using one of the following options:
React
or
PHP's built-in web server
Which has more performance? In definitely, what is the best? Which is your recommendation?
I always used Apache for my PHP projects. But now, I want to leave it, to start using one of the following options:
React
or
PHP's built-in web server
Which has more performance? In definitely, what is the best? Which is your recommendation?
PHP's built-in webserver is only meant for development and testing. It's a simple server that was never intended to handle real world loads.
An event-driven server would just add a bunch of needless complexity unless you really the features it adds.
Neither of them are intended for any serious or general purpose server. Unless you have a concrete reason to use a different stack, you should stick with Apache. It's stable, secure, configurable and does the job really well.
Ok, so there's this cool thing called nginx. DONT STOP READING YET
One of the things that a lot of people don't realize is that nginx can do proxy requests, very quickly and very efficiently.
You may ask, what is a proxy request?! Then good.
A proxy request is recieved from the remote user to nginx. Nginx will receive that, and then forward the request along to another listener. This listener can be a unix domain socket, Apache, another nginx server on the network, or even the internal PHP built-in server.
Personally, it sounds like you don't know much about PHP-FPM, which is a socket-based parser for PHP. Back in the old days of Apache, people used to use this thing called
mod_php
where Apache would manually parse the request using the shared library. This was HORRIBLE.If you are looking to leave because of that reason, I'd suggest upgrading, and boosting your performance by using PHP-FPM with Nginx. Rackspace has a nice article on this: http://www.rackspace.com/knowledge_center/article/installing-nginx-and-php-fpm-setup-for-nginx
Snippet:
Example nginx config:
That
location ~ \.php$
route will forward all PHP requests to your php-fpm instance. Of course, update your nginx config to match your socket name.If you wanted to use this with the built-in PHP server you can do (assuming it's running on localhost:8000):
That way, you can have best of both worlds. (Remember though, the internal PHP server is not optimized or hardened. I suggest PHP-FPM.