Find if the installed PHP is threadsafe or nonthreadsafe?

PhpIisThread Safety

Php Problem Overview


How do I find out whether the installed version of PHP is threadsafe or not thread safe?

Please note that I'm not asking the difference between a threadsafe/non thread safe installation. I would like to find out what is installed currently.

Php Solutions


Solution 1 - Php

Open a phpinfo() and search for the line Thread safety. For a thread-safe build you should find enable.

As specified in the comments by Muhammad Gelbana you can also use:

  • On Windows : php -i|findstr "Thread"
  • On *nix: php -i|grep Thread

Solution 2 - Php

If you prefer to use the command line:

  • *nix:

      php -i | grep -i "Thread"
    
  • Windows:

      php -i | findstr -i "thread"
    

This should give you something like this:

Thread Safety => enabled

or

Thread Safety => disabled

Solution 3 - Php

I just find it easier to look at the file named php[version].dll in the root folder of php. Its either php[version].dll or php[version]ts.dll (ts standing for Thread Safe). So, if you have php7.0.10 installed, go to the directory that has this name and you'll find a file named php7ts.dll. This is a very sad way of finding out, but it works!

Solution 4 - Php

Then there's the undocumented ZEND_THREAD_SAFE constant, which seems to exist since PHP 4.3.

<?php

if (ZEND_THREAD_SAFE) {
    echo 'Thread safe';
} else {
    echo 'Not thread safe';
}

https://3v4l.org/tALKX

Solution 5 - Php

Create a new PHP file and insert this code in it:

<?php
phpinfo(); ?>

Then run this page and you will find all of the PHP information. Search for the term that you want, and it will show you it's enabled.

Solution 6 - Php

Check if your install is Apache Module or CGI Binary. See Stack Overflow question https://stackoverflow.com/questions/1623914.

Solution 7 - Php

Another way to check it is using php -v or php --version. Example bellow from mine (NTS):

    $ php --version
    
    PHP 7.3.25-1+ubuntu20.04.1+deb.sury.org+1 (cli) (built: Dec 26 2020 10:32:51) ( NTS )       
    Copyright (c) 1997-2018 The PHP Group
    Zend Engine v3.3.25, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.25-1+ubuntu20.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJoshView Question on Stackoverflow
Solution 1 - PhpgrunkView Answer on Stackoverflow
Solution 2 - PhpMattView Answer on Stackoverflow
Solution 3 - PhpFlemin AdambukulamView Answer on Stackoverflow
Solution 4 - PhpShiraNai7View Answer on Stackoverflow
Solution 5 - PhpperoxideView Answer on Stackoverflow
Solution 6 - PhpPhliplipView Answer on Stackoverflow
Solution 7 - PhpJulyano FelipeView Answer on Stackoverflow