DEV Community

Cover image for PHP vs Node.js: A Real-World Performance Comparison
Suresh Ramakrishnan
Suresh Ramakrishnan

Posted on

PHP vs Node.js: A Real-World Performance Comparison

Objective

In recent times, there’s been a noticeable industry shift toward Node.js for developing REST APIs, even though mature languages like Java, Python, and PHP already exist. This motivated me to evaluate Node.js performance against PHP, which is less commonly used in the industry today — even though many CMS platforms and web applications still rely on it.

Before choosing the right server-side scripting technology, I wanted to check how efficiently each one handles HTTP requests.

So, I decided to measure their real-world performance under load.

The goal was to find how Traditional PHP (with Apache), Modern Laravel Octane, and Node.js (with NestJS) behave under concurrent traffic.

But before diving into the results, let’s first understand how each of them processes requests.

PHP (with Apache HTTP Server)

Traditional PHP runs in a request-per-process model.
Each HTTP request spawns a new PHP process or thread under Apache’s mod_php module.
After execution, the process ends — meaning the entire runtime and application state are re-initialized for every request

Laravel Octane (with RoadRunner)

Laravel Octane introduces a persistent application server that keeps the Laravel app in memory between requests.

It uses *RoadRunner *(or Swoole) as the server, drastically reducing startup cost per request.

Node.js (NestJS Framework)

Node.js uses an event-driven, non-blocking I/O model.
It runs on a single thread but uses an event loop to handle thousands of concurrent connections efficiently without creating a new process per request.

Test Setup

API Endpoint: Get User Data(10 records)
Concurrent Users: 50 (VUs)
Duration: 10 seconds
Load Test Tool: k6 (Grafana)

Test Results

Framework / Stack Requests Count Mean Duration (ms) P95 (ms) P99 (ms) Mean RPS Max RPS
PHP + Apache 107 6096.39 15197.79 15548.40 6.68 8.0
Laravel Octane (RoadRunner) 2311 217.91 288.76 729.08 231.1 247.67
NestJS (Node.js) 5237 95.67 130.04 402.85 585.33 247.67

In short — if performance and scalability are your goals, Node.js (NestJS) leads the pack

Top comments (0)