2

It has been weeks now that I cannot install pthreads. I am going to list the error logs then I will list my configuration options.
These are the errors I get:
(Apache Error Log)

The apache2handler SAPI is not supported by pthreads in Unknown on line 0

apachectl -V output

Server version: Apache/2.4.18 (Unix) Server built: Jan 10 2016 14:54:48 Server's Module Magic Number: 20120211:52 Server loaded: APR 1.4.8, APR-UTIL 1.5.2 Compiled using: APR 1.4.8, APR-UTIL 1.5.2 Architecture: 64-bit Server MPM: worker threaded: yes (fixed thread count) forked: yes (variable process count)

Meanwhile PHP error logs:
(PHP Error Log)
bin/php -m
PHP Warning: Module 'pthreads' already loaded in Unknown on line 0 [PHP Modules] Core date pcre pthreads Reflection SPL standard

There is no another ini files that loads extension=pthreads.so, All these errors only occur when I include extension=pthreads.so into php-cli.ini file.

Without php-cli.ini file, php -m lists these modules: bin/php -m
[PHP Modules] Core date pcre Reflection SPL standard

At this point PHP AND APACHE work perfectly except pthreads class is not recognized.

Apache Configuration Options ./configure \ --prefix=path/apache \ --exec-prefix=path/apache \ --with-pcre=path/apache/pcre \ --enable-module=so \ --with-mpm=worker

PHP Configuration Options ./configure \ --prefix=path \ --exec-prefix=path \ --with-apxs2=path/apache/bin/apxs \ --with-config-file-scan-dir=path/php/lib \ --with-config-file-path=path/php/lib \ --disable-all \ --enable-maintainer-zts \ --enable-pthreads=shared

D.elp
  • 121
  • 1
  • 6

2 Answers2

3

Because, again and again, pthreads is NOT supported by apache (PHP-CGI), only by CLI version

https://github.com/krakjoe/pthreads

SAPI Support

pthreads v3 is restricted to operating in CLI only: I have spent many years trying to explain that threads in a web server just don't make sense, after 1,111 commits to pthreads I have realised that, my advice is going unheeded.

So I'm promoting the advice to hard and fast fact: you can't use pthreads safely and sensibly anywhere but CLI.

Thanks for listening ;)

  • PHP needs to get with the times and come up with a reliable multi-threading or asynchronous solution. Otherwise backend web servers will have no choice but to switch to something more capable such as node. Can you provide a reference to why multi-threading does not make sense for web requests? – srayner May 08 '17 at 20:21
  • Asynchronous operations are sensible for web requests, but threads are not. – SOFe Dec 19 '17 at 10:08
-1

So far I think you know why you were getting that error. If you want to use pthreads in CLI and JUST CLI (you know why) and not load it in apache you have two options. 1- compile php with --enable-pthreads=shared option. for that you should download pthreads in /path/php/ext and remove configure file, then do ./buildconf --force to build a clean configure, and finally ./configure --enable-pthreads=shared will work just fine. do not add this extension in php.ini. 2- compile pthreads source with phpize and run any php script with -d extention={path_to_pthreads.so}.

ali
  • 1