About PHP's thread safety mode (Thread Safety)

  

PHP itself does not support threads, but it involves a thread-safe issue during installation. Windows provides two installation packages, compiled and installed under Linux. The option –enable-maintainer-zts is provided.

Many people think that it is a good thing to see "safety", but it is not.

Since PHP has no threads, what does this thread safety mean? This is related to how it works. Here are just two of the popular PHP operating modes (LNMP and LNAMP) under Linux.

If it is an LNMP environment, that is to say PHP is running in php-fpm mode, then thread security is not involved, because php-fpm is run in a multi-process manner. If you are running LNAMP or LAMP (mod_php), you should first understand the Apache MPM. To put it simply, Apache supports multi-threaded (Worker) and multi-process (Prefork). In general, most of the Apache under Linux is running in Prefork mode, which is for stability reasons.

So, under the conclusion, LNMP does not need thread safety. For stability considerations under Apache, it is recommended to run in a multi-process manner (Prefork), which does not require thread safety.

Finally, PHP is installed as thread-safe, it takes more CPU than non-thread-safe, and may increase bugs or instability. This is the point, otherwise PHP does not need to set this option. .

Copyright © Windows knowledge All Rights Reserved