duanchui1251 2010-01-10 20:59
浏览 81
已采纳

PHP:pcntl_fork()真正做什么?

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?

  • 写回答

4条回答 默认 最新

  • dqnz43863 2010-01-10 21:10
    关注

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

    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.


    But, quoting the Introduction of the Process Control section of the manual :

    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.

    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 :

    Note: This extension is not available on Windows platforms.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况