1

Today I came across the following statement from PHP Manual:

The web server runs only one single-threaded process, so PHP applications will stall if a request is blocked.

After reading and trying to understand the above statement firstly I didn't understand the actual and exact meaning of the term single-threaded process specific to PHP.

Secondly, I didn't understand the second part of this statement as below

so PHP applications will stall if a request is blocked.

I didn't understand what request gets blocked when and how? Which PHP applications get stalled?

So, can someone please explain to me the actual and exact meaning of the above entire statement with specific meaning to PHP and with a suitable example?

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • 1
    PHP's built-in web server can handle exactly _one_ request at a time. If you try to make a second request before the first is finished, that new request will be blocked until the first completes. The built in web server is for development/debugging only, and is generally _wildly_ inadequate for those purposes anyway. – Sammitch Oct 07 '22 at 21:12

1 Answers1

0

PHP's web server cannot process multiple requests at the same time. It's single-threaded and doesn't spool additional processes like Apache or Nginx do.

Let's say you start the web server and it listens on localhost:8080. You write the following code as the only logic:

<?php
sleep(5);
echo 'Hello world!';

You then open two tabs in your browser and you navigate to localhost:8080 in both tabs at the same time. The first tab shows content after 5 seconds, while the second one is stalled until the first one finishes and then takes another 5 seconds to execute. This means that the second tab will show content only after 10 seconds.

it took me almost a second to switch tabs and press F5

Dharman
  • 30,962
  • 25
  • 85
  • 135