简体   繁体   English

PHP Pthread类中的Yii框架上下文

[英]Yii Framework Context in PHP Pthread Class

I'm working on PHP Pthreads . 我正在研究PHP Pthreads I have written a class which inherits the "Thread" class. 我写了一个继承“Thread”类的类。 This class does not recognize the Yii (1.x) framework context. 此类无法识别Yii(1.x)框架上下文。 I cannot use any of the Yii framework components or models. 我不能使用任何Yii框架组件或模型。 I have made sure the thread class should reside in the Yii framework's accessible paths defined in the "import" in configuration. 我确保线程类应该驻留在Yii框架的配置中“import”中定义的可访问路径中。

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. 这是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

You need to install pthreads in your system. 您需要在系统中安装pthread。

For Wampp (Windows) 对于Wampp(Windows)

  1. Find out what is your 'PHP Extension Build' version by using phpinfo(). 通过使用phpinfo()找出你的'PHP Extension Build'版本。 You can use this - http://localhost/?phpinfo=1 你可以使用它 - 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). 下载与您的php版本(32位或64位)和php扩展版本(当前使用的VC11)匹配的pthread。 Use this link for download - http://windows.php.net/downloads/pecl/releases/pthreads/ 使用此链接进行下载 - http://windows.php.net/downloads/pecl/releases/pthreads/

  3. Extract the zip - Move php_pthreads.dll to the 'bin\\php\\ext\\' directory. 解压zip - 将php_pthreads.dll移动到'bin \\ php \\ ext \\'目录。

    Move pthreadVC2.dll to the 'bin\\php\\' directory. 将pthreadVC2.dll移动到'bin \\ php \\'目录。

    Move pthreadVC2.dll to the 'bin\\apache\\bin' directory. 将pthreadVC2.dll移动到'bin \\ apache \\ bin'目录。

    Move pthreadVC2.dll to the 'C:\\windows\\system32' directory. 将pthreadVC2.dll移动到'C:\\ windows \\ system32'目录。

  4. Open php\\php.ini and add extension=php_pthreads.dll 打开php \\ php.ini并添加extension = php_pthreads.dll

Now restart server and you are done. 现在重启服务器,你就完成了。

For LINUX SYSTEM'S: 对于LINUX SYSTEM'S:

1) Download PHP sources and Unpack PHP 1)下载PHP源代码并解压缩PHP

2) Download PEAR wget http://pear.php.net/go-pear.phar php go-pear.phar 2)下载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) 3)下载pthreads获取PECL扩展(PECL是PHP扩展的存储库)

pecl install pthread-0.4.4 pecl安装pthread-0.4.4

4) Unpack pthreads copy pthread-0.4.4 to php/ext (for ./configure allow add option --enable-pthreads) 4)解压缩pthreads将pthread-0.4.4复制到php / ext(对于./configure允许添加选项--enable-pthreads)

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

5) Reconfigure sources 5)重新配置源

./buildconf --force ./buildconf --force

./configure --help | ./configure --help | grep pthreads grep pthreads

You should see the appropriate --enable-pthreads option listed as a result, if you do not, then 您应该看到相应的--enable-pthreads选项作为结果列出,如果不这样做,那么

rm -rf aclocal.m4 rm -rf aclocal.m4

rm -rf autom4te.cache/ rm -rf autom4te.cache /

./buildconf --force ./buildconf --force

6) Build PHP Compile PHP source code Add: 6)构建PHP编译PHP源代码添加:

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

7) Installing PHP 7)安装PHP

make 使

sudo make install sudo make install

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

9) Check Modules php -m (check pthread loaded) 9)检查模块php -m(检查pthread加载)

10) Test Thread Class 10)测试线程类

php SimpleTest.php php SimpleTest.php

This Link will explain better. 链接将更好地解释。

Hope this will help you :) 希望这个能对您有所帮助 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM