PHP: What does pcntl_fork() really do?

前端 未结 4 1560
执念已碎
执念已碎 2021-01-02 00:37

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

4条回答
  •  天涯浪人
    2021-01-02 01:06

    I'll try to be quick and concise,

    Using "fork" through apache it is possible, you need to "install" then enable the functions in the php.ini, finally you need to add the extension in the apache directori (a symlink would have the job done as well) Ex:

    echo "extension=pcntl.so" > /etc/php5/conf.d/pcntl.ini
    ln -s /etc/php5/apache2/conf.d/pcntl.ini /etc/php5/mods-available/pcntl.ini 
    

    On the other hand, I've been using forking for a lot of projects and it is really great at optimizing most of them, however, there is a bug when abusing of it with apache, im basically forking the forked child and doing anykind of hardcore stuff and it works... pretty good, but under load it works for some time before start to creating zombie process, i can manage the zombie process using "pcntl_signal(SIGCHLD, SIG_IGN);" which basically will remove the process as soon as the child finish their task, this help a little bit, then is when apache goes crazy, and start threading itself and finally crashing your server, i cannot explain this behavior (yet, but i will) this weir/evil tree created by apache can only be seen from "ps" nor from server-status or apache logs, and i said evil tree because it basically creates hundred of process with children of children...

    in nutshell:

    Fork with apache will work? YES... absolutely

    just dont abuse of it

    hope this will help some one

提交回复
热议问题