2017 © Pedro Peláez
 

library async

image

sanderswang/async

  • Wednesday, May 16, 2018
  • by sanderswang
  • Repository
  • 1 Watchers
  • 0 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Notice

if in WEB server and want to do something async pls consider fastcgi_finish_request(), (*1)

#, (*2)

Async

fork from muyizixiu/Async , (fix small bugs), (*3)

php 异步任务库
一个快速响应的web应用必然有很多繁重的异步任务去做,Async利用pnctl_fork创建异步进程,同时管理异步任务。

detai: https://github.com/muyizixiu/Async, (*4)

Install

composer install sanderswang/async

Usage

common async task:

use Async/Async;
$async = new Async($redis_host,$redis_port,$redis_password,'/tmp/async);
$async->task(function($data){
    echo 'common Async' . "$data\n";
    doSomething();
}, 'common task');

do once, and then exit, (*5)

#

domain and queue task:

domain.php, (*6)

use Async/Async;
$a = new Async($redis_host,$redis_port,$redis_password,'/tmp/async');
//当任务不存在时创建任务
if(!$a->isTaskExists($task_name)){
    $a->task(function($data){
        echo 'hello Async'."$data\n";
        doSomething();
    },$task_name,true,true,'123');
}

a.php:, (*7)

$a = new Async($redis_host,$redis_port,$redis_password,'/tmp/async');
for($i = 0;$i < 10;$i ++){
    sleep(2);
    $a->sendData($task_name, "这是我第$i个数据");
}

以上代码模拟定时任务。 该异步进程一旦启动则常驻,不会每隔10秒启动一个异步进程,而是在同一个进程里面,不停的接受投递过来的参数。, (*8)

依赖

本库依赖redis实现进程管理,需安装redis扩展,并提供账号和密码。, (*9)

The Versions

16/05 2018

dev-master

9999999-dev

  Sources   Download

by Avatar sanderswang

18/06 2017

dev-Async1.0.0

dev-Async1.0.0

  Sources   Download

by Avatar muyizixiu

18/06 2017

v1.0.0

1.0.0.0

  Sources   Download

by Avatar muyizixiu