I'm trying to implement threads in php and with xampp on windows I can do this, however i have a linux server with cpanel and in configurations the Thread Safety is disabled, how can i put enabled on my server linux? I call phpinfo() and it shows that "Thread Safety" is disabled
3 Answers
You have two options:
- Find a thread safe package in your distributions package repository
- Compile PHP from source with
--enable-maintainer-zts
I'm quite sure cPanel has a configuration screen that will allow you to reconfigure and rebuild, a quick google turns up this, which appears relevant:
http://forums.cpanel.net/f442/how-install-php-pthreads-zts-387252.html

- 17,032
- 5
- 41
- 62
'Thread safety' has nothing to do with any PHP script that you write, including if you want to use threads or not. It is referring to the style of server that is running PHP:
apache running PHP as CGI, the PHP process is started separately from the Apache worker in its own process. A threadsafe binary is not required.
apache with mod-php, the PHP is run as a thread within the apache worker process. A threadsafe binary is required.
See this answer for a more detailed explanation.
-
2You say *nothing to do with any PHP script that you write, including if you want to use threads or not*. Does that mean I can extend the class `Thread` regardless of the thread safety being active or not in the host PHP? – Lucio Crusca Nov 26 '16 at 14:05
You do not need to enable Thread Safety
as it won't make any difference to your code. For better understanding
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. Thread Safety works by creating a local storage copy in each thread so that the data will not collide with another thread.
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.

- 5,484
- 7
- 53
- 78