126

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/… Commented 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? Commented Apr 27, 2011 at 5:45

7 Answers 7

221

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
Sign up to request clarification or add additional context in comments.

3 Comments

On Windows: php -i|find "Thread" On *nix: php -i|grep Thread
Note to self: php -i | find "Architecture" to check if it is x86 or x64
@checksum it's php -i | grep Architecture
28

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 Comment

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).
12

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

Comments

9

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!

Comments

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.

Comments

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 Comments

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
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?
yeah,phpinfo had the info in it...Just found it...Thanks @Philiplip
2

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 

1 Comment

I'm compiling an old 5.3 build for a client (yikes I know), and the '(NTS)' doesn't appear for me but I'm definitely non-ZTS as my version, I'm not sure when this appeared, but it's not in much older versions it seems.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.