Creation of new process for each request of web page?

╄→尐↘猪︶ㄣ 提交于 2019-12-18 04:45:08

问题


It might be a basic question but everytime a user call a php file from a server, does it create a new process from that server ?

For example, I have a basic form (let's say on index.php) that submits a text to another php file. In that php file, I print the posix_getpid().

I opened in two tabs my index.php an filled in and submitted a text and I ended up with two different pid on each tab.

Which lead me to the conclusion that a server probably create a new process for each script. Am I right ?

Cheers !


回答1:


I assume that you're running apache as your web server.

When a request comes in, apache starts a new thread. PHP is then invoked on this new thread, hence why you get a new process id every time.

This is, of course, greatly simplified.

I recommend reading this article for a deeper understanding.

Edit: It seems that the process differs between platforms. It works the way I described above on Windows, but multiple apache processes are executed on Unix.




回答2:


There are multiple ways to chain the web server with PHP.

For Apache HTTP Server, the most popular is "mod_php". This module is actually PHP itself, but compiled as a module for the web server, and so it gets loaded right inside it. Since with mod_php, PHP gets loaded right into Apache, if Apache is going to handle concurrency using its Worker MPM (that is, using Threads)

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

With Nginx you won't have the option to embed PHP into it. Hence, PHP is totally outside of the web server with multiple PHP processes.

And it is good, because PHP can do things on lower lever, like changing locales And setlocale() is NOT thread-safe.



来源:https://stackoverflow.com/questions/5171639/creation-of-new-process-for-each-request-of-web-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!