PHP code example of yizixiumu / async

1. Go to this page and download the library: Download yizixiumu/async library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yizixiumu / async example snippets


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

use Async;
$redis_host = "localhost:6379";
$redis_user = "async";
$redis_password = "";
$task_name = 'queued task';
$a = new Async($redis_host,$redis_user,$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->task(function($data){
    echo 'hello Async'."$data\n";
    doSomething();
},$task_name,true,true,'123');

for($i = 0;$i < 10;$i ++){
    sleep(10);
    $a->sendData($task_name,"这是我第$i个数据");
}