114

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.

2
  • 1
    see answer in stackoverflow.com/questions/1623914/…
    – Haim Evgi
    Apr 27, 2011 at 5:41
  • 1
    @Haim Thats not my question Haim. I saw that thread. I have PHP already installed on this server. Its working with IIS. But,I need to findout which setup was used to install this...Threadsafe setup/ the non theadsafe setup?
    – Josh
    Apr 27, 2011 at 5:45

7 Answers 7

204

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
3
  • 18
    On Windows: php -i|find "Thread" On *nix: php -i|grep Thread Sep 2, 2013 at 9:33
  • 8
    Note to self: php -i | find "Architecture" to check if it is x86 or x64
    – checksum
    Mar 7, 2015 at 15:06
  • @checksum it's php -i | grep Architecture
    – helpse
    Jul 14, 2017 at 20:01
24

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
1
  • 1
    Not a very good idea, since the PHP version used by the server can be different from the one picked up by the OS (the default).
    – Buffalo
    Aug 2, 2017 at 7:18
8

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!

5

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

4

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.

2

Check if your install is Apache Module or CGI Binary. See Stack Overflow question What is thread safe or non-thread safe in PHP?.

3
  • How do I check that? Ofcourse its being used by IIS..But how do I findout what module it is? That was my question...I don't mean to ask the difference between threadsafe/non thread safe. I need to know whether the installed version is thread safe/not
    – Josh
    Apr 27, 2011 at 5:43
  • Ok i just investigated a bit, and yes there are 2 builds available; safe and non-safe. According to this install guide for IIS7 non-thread-safe installs are recommended. Could you open up a phpinfo() and se if the word 'thread' apears anywhere?
    – Phliplip
    Apr 27, 2011 at 6:02
  • yeah,phpinfo had the info in it...Just found it...Thanks @Philiplip
    – Josh
    Apr 27, 2011 at 7:56
1

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

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.