2017 © Pedro Peláez
 

yii2-extension yii2-thread

yii2 multi thread with fsockopen

image

kriss/yii2-thread

yii2 multi thread with fsockopen

  • Monday, May 15, 2017
  • by kriss
  • Repository
  • 1 Watchers
  • 2 Stars
  • 97 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 5 % Grown

The README.md

yii2 multi thread

yii2 使用 fsockopen 模拟多线程操作, (*1)

安装

推荐使用 composer., (*2)

php composer.phar require --prefer-dist kriss/yii2-thread "*"

或添加下面代码到composer.json文件, (*3)

"kriss/yii2-thread": "*"

然后使用, (*4)

php composer.phar update

使用方式

1.进行配置, (*5)

basic 模版为 config/web.php, advanced 模版为对应入口的 config/main.php, (*6)

示例配置如下:, (*7)

'components' => [
    ...
    'thread' => [
        'class' => 'kriss\thread\components\Thread',
        'enable' => true,
        'tokenValidate' => true, // 是否开启 url token 验证,默认开启
        'tokenParam' => 'token', // token 参数名
        'token' => 'suiyitianxiezijidetoken', // 随意填写自己的验证 token
    ],
    ...
]

2.继承和改写, (*8)

编写控制器来接收异步处理的链接, (*9)

继承 \kriss\thread\controllers\WebThreadController 然后编写对应的 Action, (*10)

3.使用, (*11)

比如控制器下有个 Action 如下:, (*12)

public function actionSendMessage($message)
{
    Yii::info($message);
}

则在需要调用异步处理的脚本中使用:, (*13)

Yii::$app->thread->addThread(['/web-thread/send-message','message'=>'hello world']);

链接['/web-thread/send-message','message'=>'hello world'] 将会在"本次请求脚本执行结束之前"(参考:register_shutdown_function) 使用fsockopen方式发起请求访问, (*14)

The Versions

15/05 2017

dev-master

9999999-dev https://github.com/krissss/yii2-thread

yii2 multi thread with fsockopen

  Sources   Download

MIT

The Requires

 

by Avatar kriss

yii2 thread

15/05 2017

1.1

1.1.0.0 https://github.com/krissss/yii2-thread

yii2 multi thread with fsockopen

  Sources   Download

MIT

The Requires

 

by Avatar kriss

yii2 thread

14/07 2016

1.0

1.0.0.0 https://github.com/krissss/yii2-thread

yii2 multi thread with fsockopen

  Sources   Download

MIT

The Requires

 

by Avatar kriss

yii2 thread