PHP with Thread Safety enabled

Asked by ReynierPM

I have been using IUS repositories for a while and it's good (I prefer this one over REMI). Recently I need to use multithreading in a PHP application I am working on so I install php56u-pecl-pthreads and try to enabled it on php.ini but surprise I can't and I end with this error: Failed loading /usr/lib64/php-zts/modules/pthreads.so: /usr/lib64/php-zts/modules/pthreads.so: undefined symbol: core_globals_id all the time. I open a issue at pthreads Github account (https://github.com/krakjoe/pthreads/issues/488) and they told me I need to recompile my PHP using the option --enable-maintainer-zts, could you add packages with thread safety enabled?

Question information

Language:
English Edit question
Status:
Answered
For:
IUS Community Project Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
bharper (bharper) said :
#1

Greetings,

Thanks for taking the time to contact us about this issue. Looking over the SRPM and build logs for php56u, it does appear that php56u is compiled with the --enable-maintainer-zts in all the right places. In your testing, did you do anything with the /etc/php-zts.d/40-pthreads.ini file?

-Ben

Revision history for this message
bharper (bharper) said :
#2

Attempting to install pthreads via pecl:

# rpm -qf `which pecl`
php56u-pear-1.9.5-1.ius.centos6.noarch

# pecl install pthreads-2.0.10
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
downloading pthreads-2.0.10.tgz ...
Starting to download pthreads-2.0.10.tgz (85,247 bytes)
....................done: 85,247 bytes
36 source files, building
running: phpize
Configuring for:
PHP Api Version: 20131106
Zend Module Api No: 20131226
Zend Extension Api No: 220131226
building in /var/tmp/pear-build-rootqA9kDa/pthreads-2.0.10
running: /var/tmp/pthreads/configure
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib
checking for PHP extension directory... /usr/lib64/php/modules
checking for PHP installed headers prefix... /usr/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking whether to enable Threading API... yes, shared
checking whether to enable pedantic locking... no
checking checking for ZTS... configure: error: pthreads requires ZTS, please re-compile PHP with ZTS enabled
ERROR: `/var/tmp/pthreads/configure' failed

Revision history for this message
ReynierPM (reynierpm) said :
#3

I was able to get this working by changing Apache MPM from prefork to worker at /etc/sysconfig/httpd, after that I restarted webserver and using zts-php -m I was able to see the module loaded also it appears not using phpinfo() I don't know if this is the right way although

Revision history for this message
bharper (bharper) said :
#4

I was just doing some additional testing and had the same line of thinking:

# rpm -qa |grep php
php56u-xml-5.6.13-1.ius.centos6.x86_64
php56u-pecl-jsonc-1.3.9-1.ius.centos6.x86_64
php56u-pecl-pthreads-2.0.10-2.ius.centos6.x86_64
php56u-cli-5.6.13-1.ius.centos6.x86_64
php56u-common-5.6.13-1.ius.centos6.x86_64
php56u-5.6.13-1.ius.centos6.x86_64
php56u-pear-1.9.5-1.ius.centos6.noarch
php56u-pecl-jsonc-devel-1.3.9-1.ius.centos6.x86_64
php56u-process-5.6.13-1.ius.centos6.x86_64
php56u-devel-5.6.13-1.ius.centos6.x86_64

# zts-php -v
PHP 5.6.13 (cli) (built: Sep 3 2015 11:57:13)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies

# zts-php -m
[PHP Modules]
bz2
calendar
Core
ctype
curl
date
dom
ereg
exif
fileinfo
filter
ftp
gettext
hash
iconv
json
libxml
mhash
openssl
pcntl
pcre
Phar
posix
pthreads
readline
Reflection
session
shmop
SimpleXML
sockets
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlwriter
xsl
zip
zlib

[Zend Modules]

# zts-php -i |grep pthreads
/etc/php-zts.d/40-pthreads.ini
PHP Warning: Unknown: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in Unknown on line 0
pthreads

# cat test-pthreads.php
<?php
class AsyncOperation extends Thread {
  public function __construct($arg){
    $this->arg = $arg;
  }

  public function run(){
    if($this->arg){
      printf("Hello %s\n", $this->arg);
    }
  }
}
$thread = new AsyncOperation("World");
if($thread->start())
  $thread->join();
?>

# zts-php test-pthreads.php
Hello World

The test-pthreads.php came from https://github.com/krakjoe/pthreads/blame/master/README.md#L57-L78.

-Ben

Can you help with this problem?

Provide an answer of your own, or ask ReynierPM for more information if necessary.

To post a message you must log in.