Creating a new process for every web page request?

This may be the main question, but every time the user calls the php file from the server, he creates a new process from this server?

For example, I have a basic form (say, at index.php) that sends text to another php file. In this php file, I type posix_getpid () .

I opened my index.php index in two tabs, filled and sent the text, and I ended up with two different pid on each tab.

Which led me to conclude that the server is probably creating a new process for each script. I'm right?

Greetings!

+9
source share
2 answers

I assume that you are using apache as your web server.

When the request arrives, apache starts a new thread. Then PHP is called on this new therad, so every time you get a new process id.

This, of course, is greatly simplified.

I recommend reading this article for a deeper understanding.

Edit: It seems that the process is different between platforms. It works as I described above on Windows, but several apache processes run on Unix.

+5
source

There are several ways to associate a web server with PHP.

For Apache HTTP Server most popular is "mod_php". This module is actually PHP itself, but compiled as a module for the web server, and therefore it loads directly into it. Since with mod_php, PHP loads directly into Apache if Apache is going to handle concurrency using its Worker MPM (i.e. using Threads)

And here is a trap for things like setlocale() .

With Nginx you will not be able to embed PHP in it. Consequently, PHP is completely outside the web server with several PHP processes .

And this is good, because PHP can do something at a lower level, for example, change locales and setlocale() NOT thread-oriented.

0
source

All Articles