开发者

What are "multiple processes" in PHP?

"I would prefer it to be written in PHP or Java (I know PHP can't do multiple threads, but it could be accomplished with multiple processes)".

What do开发者_如何学Ces this statement mean when it says "multiple processes"? Are there any good examples out there?


A process it more or less a program launch. For instance if you launch a web server two times you will have two process, which will be able to respond to different requests at the same time.

A thread is more or less a sub-process inside a process. That way web server usually have multiple thread handling requests from different users. That mean that multiple requests can be handled at the same time by only one process.


Multiple-processes means several processes, probably executed in parallel.

And a "process" is just an execution of a program.

So, multiple-processes means several executions of a program -- in parallel, to achieve some kind of multiple-threads result : instead of having one program with several threads, which is not possible in PHP, you launch the same program more than once in parallel (and, generally, each instance of a program will work with a subset of the total amout of data).


The best example of "multiple processes" is Apache httpd itself. Starting it brings up a "parent" process which then starts one or more "child" processes that handle the requests:

# ps auxfww | grep '[h]ttpd'
root      8632  0.0  0.2 247376  8380 ?        Ss   05:57   0:00 /usr/sbin/httpd
apache    8635  0.0  0.1 247376  4716 ?        S    05:57   0:00  \_ /usr/sbin/httpd
apache    8636  0.0  0.1 247376  4716 ?        S    05:57   0:00  \_ /usr/sbin/httpd
apache    8637  0.0  0.1 247376  4716 ?        S    05:57   0:00  \_ /usr/sbin/httpd
apache    8638  0.0  0.1 247376  4716 ?        S    05:57   0:00  \_ /usr/sbin/httpd
apache    8639  0.0  0.1 247376  4716 ?        S    05:57   0:00  \_ /usr/sbin/httpd
apache    8640  0.0  0.1 247376  4716 ?        S    05:57   0:00  \_ /usr/sbin/httpd
apache    8641  0.0  0.1 247376  4716 ?        S    05:57   0:00  \_ /usr/sbin/httpd
apache    8642  0.0  0.1 247376  4716 ?        S    05:57   0:00  \_ /usr/sbin/httpd
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜