Open In App

What is thread safe or non-thread safe in PHP ?

Improve
Improve
Like Article
Like
Save
Share
Report

Thread-safe: It is used to ensure that when the shared data structure which is manipulated by different threads are prevented from entering the race condition. Thread-safety is recommended when the web server run multiple threads of execution simultaneously for different requests. In Thread Safety binary can work in a multi-threaded web server context. Thread Safety works by creating a local storage copy in each thread so that the data will not collide with another thread.
For example:

  • Apache + LoadModule
  • IIS

Non-thread-safe: It does not check the safety of the threads which makes it faster to run but at the same time, it becomes more unstable and crashes very frequently. It refers to a single thread only builds. In non-thread safe version binaries widespread use in the case of interaction with a web server through the FastCGI protocol, by not utilizing multi-threading.
For example:

  • Apache + FastCGI
  • IIS + FastCGI

So it depends on the way that you want to use PHP. AFAIR running PHP with the fastCGI is the preferable way. If you are unknown which version of PHP is installed in your system then there is an easy way to know that.
Check the version of installed PHP Thread safe or Non Thread Safe:
Open a phpinfo() and search for the line Thread safety for a thread-safe build you should find enable.

  • On Windows:
    php -i|findstr "Thread"
    
  • On *nix:
    php -i|grep Thread
    
  • In the both cases will display any one
    Thread Safety => enabled
    //or
    Thread Safety => disabled
    

Last Updated : 17 Jul, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads