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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Josh
  • 1,287
  • 3
  • 10
  • 12
  • 1
    see answer in http://stackoverflow.com/questions/1623914/what-is-thread-safe-or-non-thread-safe-in-php – Haim Evgi Apr 27 '11 at 05: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 '11 at 05:45

7 Answers7

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
Community
  • 1
  • 1
grunk
  • 14,718
  • 15
  • 67
  • 108
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
azjezz
  • 3,827
  • 1
  • 14
  • 35
Matt
  • 2,713
  • 5
  • 27
  • 35
  • 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 02 '17 at 07: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

Shira
  • 6,392
  • 2
  • 25
  • 27
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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
peroxide
  • 696
  • 1
  • 4
  • 19
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?.

Community
  • 1
  • 1
Phliplip
  • 3,582
  • 2
  • 25
  • 42
  • 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 '11 at 05:43
  • Ok i just investigated a bit, and yes there are [2 builds](http://windows.php.net/download/) available; safe and non-safe. According to this [install guide for IIS7](http://www.php.net/manual/en/install.windows.iis7.php) non-thread-safe installs are recommended. Could you open up a phpinfo() and se if the word 'thread' apears anywhere? – Phliplip Apr 27 '11 at 06:02
  • yeah,phpinfo had the info in it...Just found it...Thanks @Philiplip – Josh Apr 27 '11 at 07: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
Julyano Felipe
  • 288
  • 2
  • 22