3

I would like use pthreads with php 7.0.8 (ZTS) (Manually compiled and configured) I have add the followinG configuration during compiling of php :

--enable-maintainer-zts \
--enable-pthreads=shared \
--with-tsrm-pthreads \

NOTICE: fpm is running, pid 25546

NOTICE: ready to handle connections

I add pthread extension with pecl : pecl install pthreads-3.1.6 and I add extension=pthreads.so into my php.ini. But after restarting php7-fpm, php-fpm not running :

NOTICE: Finishing ...

NOTICE: exiting, bye-bye!

I have a 502 nginx error.

How I can add this extension in my php.ini without exit php-fpm ?

Community
  • 1
  • 1
Dev Loots
  • 708
  • 9
  • 28

1 Answers1

3

You should use php-cli for use pthreads. You can create a second php.ini configuration for CLI :

  • First, copy if not exist your php.ini to php-cli.ini :

    cp /PATH_OF_YOUR_PHP_INSTALLATION/php.ini /PATH_OF_PHP_INSTALLATION/php-cli.ini
    
  • Then, install pthreads with PECL (if php is compiled with --enable-maintainer-zts \ --enable-pthreads=shared \ --with-tsrm-pthreads )

    pecl install pthreads
    
  • Then, add the configuration of the extension into your php-cli.ini :

    echo "extension=/PATH_OF_EXTENSION/pthreads.so" >>/PATH_OF_PHP_INSTALLATION/php-cli.ini
    
  • Finnaly, restart your php7-fpm service :

    service php7-fpm restart
    

You can test the pthread installation is working to create a test class and execute it with php : Create file : ImportWorker.php

<?php
class ImportWorker extends Worker {
    private $data;

    public function __construct($_data) {
        $this->data = $_data;//
    }

    public function run(){
        var_dump("Worker test");
    }
}

Execute that : php ImportWorker.php -> If you have any errors, that is pthreads is not working.

DevLoots
  • 747
  • 1
  • 6
  • 21