4

I'm working on PHP Pthreads. I have written a class which inherits the "Thread" class. This class does not recognize the Yii (1.x) framework context. I cannot use any of the Yii framework components or models. I have made sure the thread class should reside in the Yii framework's accessible paths defined in the "import" in configuration.

Here is an example how I wrote the thread class.

  <?php

    class MultiThreaded extends Thread {


            public function __construct(){

            }

            public function run(){
                       echo Yii::app()->basePath;
            }


    }

Update:

Here is the importer array in Yii config.

'import'=>array(
        'application.models.*',
        'application.components.*',
        'application.components.multithreaded-operations.*',
        'application.components.google_api_Lib.src.*',
        'application.controllers.*',
        'application.extensions.yii-mail.*',
        'application.extensions.*',
        'application.commands.*',

    ),  

Am I doing something wrong ?

Thanks

Arfeen

Arfeen
  • 2,553
  • 5
  • 29
  • 48

1 Answers1

0

You need to install pthreads in your system.

For Wampp (Windows)

  1. Find out what is your 'PHP Extension Build' version by using phpinfo(). You can use this - http://localhost/?phpinfo=1

  2. Download the pthreads that matches your php version (32 bit or 64 bit) and php extension build (currently used VC11). Use this link for download - http://windows.php.net/downloads/pecl/releases/pthreads/

  3. Extract the zip - Move php_pthreads.dll to the 'bin\php\ext\' directory.

    Move pthreadVC2.dll to the 'bin\php\' directory.

    Move pthreadVC2.dll to the 'bin\apache\bin' directory.

    Move pthreadVC2.dll to the 'C:\windows\system32' directory.

  4. Open php\php.ini and add extension=php_pthreads.dll

Now restart server and you are done.

For LINUX SYSTEM'S:

1) Download PHP sources and Unpack PHP

2) Download PEAR wget http://pear.php.net/go-pear.phar php go-pear.phar

3) Download pthreads Get PECL extension (PECL is a repository for PHP Extensions)

pecl install pthread-0.4.4

4) Unpack pthreads copy pthread-0.4.4 to php/ext (for ./configure allow add option --enable-pthreads)

mv build/php-src-master/ext/pthreads-master build/php-src-master/ext/pthreads

5) Reconfigure sources

./buildconf --force

./configure --help | grep pthreads

You should see the appropriate --enable-pthreads option listed as a result, if you do not, then

rm -rf aclocal.m4

rm -rf autom4te.cache/

./buildconf --force

6) Build PHP Compile PHP source code Add:

./configure --enable-debug --enable-maintainer-zts --enable-pthreads

7) Installing PHP

make

sudo make install

8) Update php.ini Add in php.ini extension=pthreads.so Include_path = “/usr/local/lib/php”

9) Check Modules php -m (check pthread loaded)

10) Test Thread Class

php SimpleTest.php

This Link will explain better.

Hope this will help you :)

Ravi Hirani
  • 6,511
  • 1
  • 27
  • 42
  • I posted this question after testing basic phthread scripts (so pthread already installed in the system). As I mentioned earlier, the question is regarding Yii framework with pthread. Thanks :) . – Arfeen Jan 19 '16 at 11:21
  • @Arfeen : As per my knowledge, There is nothing to do with Yii. If we install it in our system then we can use it in any framework. Have you tried with \Thread? – Ravi Hirani Jan 19 '16 at 11:24
  • I have already used and tested those examples. They are working with out framework. But the problem is, framework context get unset and destroyed inside pthread inherited classes. I hope you got my point. – Arfeen Jan 20 '16 at 07:31
  • @Arfeen Have you solved your thread issue in yii? I have faced samethings. If you solved that could you please post answer in your own question. That will helps to other developers. Thanks... – Developer Nov 30 '17 at 12:02