Why is the use of pcntl library in php is discoura

2019-08-02 19:19发布

问题:

Can anybody tell me why using the pcntl lib on production servers is discouraged? The PHP manual tells very briefly about it, and I'm in a dire need to use this library... Is there another way to do the same thing in php?

回答1:

pcntl is discouraged in production environments because the functionality it supports (fork, process control, signal handling) are fairly explicitly things you should not be using in a CGI style application. Now, if you're writing a daemon or command line application in PHP, that is another matter...

From the PHP manual:

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.



回答2:

one has to be clear about the differences of a php cli script and a sapi/cgi script. php on production systems may as well have support for pcntl.

the important thing here is to have 2 php config files. one for cli and one for cgi setup. one then has to disable pctnl in the cgi setup because the real security issue is, that forking a script when executed by the webserver may leave zombie processes flooding the system.

in a cli environment it might be necessary to be able to write scripts that fork...



标签: php pcntl