PHP code example of libratechie / think-asynctask

1. Go to this page and download the library: Download libratechie/think-asynctask 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/ */

    

libratechie / think-asynctask example snippets




namespace app\tasks;

class FastTask
{
    public function invoke()
    {
        // TODO: Implement the task logic here.
    }
}



return [
    // 进程名称
    'name' => 'tp_daemon',
    // 运行模式
    'daemon' => true,
    // 任务类命名空间
    'namespace' => '\\app\\tasks',
    // 任务列表
    'tasks' => [
        // FastTask:进程名称
        'FastTask' => [
            'enable' => true,   // 是否开启
            'process_num' => 1, // 进程数量
            'warning_time' => 0,    // 超时阈值
            'invoke_count' => 500,  // 单次执行循环次数
            'task_list' => [
                'FastTask' => [ // 引入的具体类名称
                    'invoke',  // 具体任务
                ]
            ]
        ]
    ]
];
shell
$ php think make:task FastTask
shell
$ php think task
shell
$ php think task status
shell
$ php think task stop