Why ZTS
is disabled by default and we should compile PHP source to achieve Threading
ability?
Is there any limitation or side effect when we enable ZTS
? Is it unstable?
Advertisement
Answer
PHP originally started out as a CGI binary, and then as a module for Apache. Neither of these two ways required PHP to be a threaded run time as they would all handle a request in sequence.
When support for other web servers, most notably Microsoft’s IIS through their ISAPI interface, was added, their processing model required PHP to be able to run as a threaded process. PHP added a “ZTS” (Zend Thread Safe) mode that does a fair bit of work to make sure that requests that run in parallel (threaded) don’t step on each others toes. But this does come at a performance cost.
As most web server APIs don’t require ZTS to be enabled, the default for PHP is for that to be off. If you were to build PHP for the ISAPI SAPI (Server Abstraction) layer, then the PHP build process automatically turns on ZTS mode.
Having said all that, the ZTS mode is not about allowing threading inside PHP scripts, but rather to allow for PHP itself to run in a threaded environment. If you are interested in running things in parallel from a PHP’s script point of view, you need to resort to third party extensions such as Joe’s parallel extension, or swoole.