PHP:什么是pcntl_fork()真的? [英] PHP: What does pcntl_fork() really do?

查看:422
本文介绍了PHP:什么是pcntl_fork()真的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP的pcntl_fork功能应该创建一个进程就像C.结果的标准fork函数
但我在想,如果这个功能真的派生的过程中,或者如果它模拟了不同方式的行为。结果
如果真的派生的过程,然后很清楚这过程是:Apache的子进程的一个结果
没关系,只要Apache是​​使用prefork MPM(每个请求即一个进程)。结果
但什么是Apache是​​否使用工人的MPM?结果发生
当使用工人MPM是,每个Apache子进程包含多个线程,每个人处理不同的HTTP请求。所以,如果你想这种情况下叉的过程中,我甚至不能想象会有什么happend到被服务的所有这些线程和请求。结果
所以,如果pcntl_fork()真的派生过程那么我认为这不是一个好主意,如果你设置Apache来使用工人MPM使用此功能。

PHP's pcntl_fork function is supposed to fork a process just as the standard fork function in C.
But I was wondering if this function really forks the process or if it emulates that behavior in a different way.
If it really forks the process then it's clear which process that is: one of Apache's child processes.
That's OK as long as Apache is using the prefork MPM (i.e. one process per request).
But what does happen if Apache is using the worker MPM??
When the worker MPM is being used, every Apache child process contains many threads, each one handling a different HTTP request. So if you would fork the process under that situation I can't even think what would happend to all those threads and requests being served.
So if pcntl_fork() really forks the process then I think it's not a good idea to use this function if you set Apache to use the worker MPM.

什么专家说?难道我的推理好,还是我只是在讲废话?

What do the experts say? Am I reasoning well, or I'm just speaking nonsense?

推荐答案

pcntl_fork 也许可以作为你认为它会:它叉当前的进程,以同样的方式C函数叉做:

pcntl_fork probably works as you think it would : it forks the current process, the same way the C function fork does :

pcntl_fork()函数创建一个
  子进程从不同
  仅在PID父进程和
  PPID。结果请参阅您的系统
  叉(2)男人特定页面
  细节到餐桌如何工作的你
  系统

The pcntl_fork() function creates a child process that differs from the parent process only in its PID and PPID.
Please see your system's fork(2) man page for specific details as to how fork works on your system.

结果
但是,引述手册中的过程控制部分的介绍:

在PHP过程控制支持
  实现过程的Unix样式
  创建,执行程序,信号
  处理和进程终止。
  结果过程控制不应该
  在Web服务器中启用
  环境和意外结果可能
  如果发生任何过程控制
  功能在Web服务器中使用的
  环境。

Process Control support in PHP implements the Unix style of process creation, program execution, signal handling and process termination.
Process Control should not be enabled within a web server environment and unexpected results may happen if any Process Control functions are used within a web server environment.

所以,你不应该实际使用该功能从通过Apache执行PHP脚本:它应该只被使用时,你的PHP脚本是在命令行中执行

So, you should not actually use that function from a PHP script executed via Apache : it should only be used when your PHP script is executed from the command-line.

结果
而且,开始使用该功能之前,不要忘了:


And, before starting to use that function, don't forget that :

注:该扩展是不可用
  在Windows平台上。

Note: This extension is not available on Windows platforms.

这篇关于PHP:什么是pcntl_fork()真的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆