Apache Vs NGINX
The main difference between Apache and NGINX lies in their design architecture. Apache uses a process-driven approach and creates a new thread for each request. Whereas NGINX uses an event-driven architecture to handle multiple requests within one thread.
Apache
NGINX Web Server
OPcache :
OPcache improves PHP performance by storing precompiled script bytecode in shared memory, thereby removing the need for PHP to load and parse scripts on each request
Basically, when you complete the code compilation in PHP, the human-readable code is converted into machine language and it takes time to compile all the scripts. So if you make a request every time and the cycle continues as the way it is, your app will face a lot of performance issues.
But having the PHP OPcache enabled, the process will run once and cache all the scripts and compile time. The scripts will be stored in memory and only the updates will compile and continue to store. This can give you a serious performance boost and can reduce the app load time significantly. Meanwhile, PHP7 OPcache uses 64MB of memory by default.
NGINX -> PHP-FPM -> Execute PHP Script -> check OpCode -> if yes then read from Shard Memory else parse compile opcode save in shard memory => execute Zend engine => Output
The main difference between Apache and NGINX lies in their design architecture. Apache uses a process-driven approach and creates a new thread for each request. Whereas NGINX uses an event-driven architecture to handle multiple requests within one thread.
Apache
- Apache HTTP Server is an open-source cross-platform web server which is also known as “httpd” and Apache.
- It is the key component of the LAMP (Linux, Apache, MySQL, PHP) stack.
- Process Driven Approach
- Creates a new thread for each request
- Serves static content using the file-based method
- Processes dynamic content within the server
NGINX Web Server
- It was used mostly for serving static files, but today, it has evolved as a complete web server that deals with the full spectrum of server tasks.
- Today, Nginx is often used as a reverse proxy, load balancer, mail proxy and HTTP caching.
- Event-Driven approach
- Handles multiple requests within one thread
- At serving static content, Nginx is the king!
- It doesn’t process dynamic content
- All the requests with dynamic web page content are passed to an external process (eg- PHP-FPM(FastCGI Process Manager)) for execution.
- NGINX can serve the dynamic content when used with SCGI handlers and FastCGI module
OPcache :
OPcache improves PHP performance by storing precompiled script bytecode in shared memory, thereby removing the need for PHP to load and parse scripts on each request
Basically, when you complete the code compilation in PHP, the human-readable code is converted into machine language and it takes time to compile all the scripts. So if you make a request every time and the cycle continues as the way it is, your app will face a lot of performance issues.
But having the PHP OPcache enabled, the process will run once and cache all the scripts and compile time. The scripts will be stored in memory and only the updates will compile and continue to store. This can give you a serious performance boost and can reduce the app load time significantly. Meanwhile, PHP7 OPcache uses 64MB of memory by default.
NGINX -> PHP-FPM -> Execute PHP Script -> check OpCode -> if yes then read from Shard Memory else parse compile opcode save in shard memory => execute Zend engine => Output
Comments
Post a Comment