PHP code example of lruisen / think-worker

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

    

lruisen / think-worker example snippets


'queue' => [
    'enable' => false, // 是否开启队列监听并执行,true:开启,false:关闭
    'workers' => [
        // 在windows系统靠此处键值开启进程,此处键值作为进程名称
        'default' => [
            'count' => 1, // 监听队列任务的进程数
            'handler' => QueueHandle::class,
            'constructor' => [
                'options' => [
                    'name' => 'default',
                    'delay' => 0,
                    'sleep' => 3,
                    'tries' => 0,
                    'timeout' => 60,
                ]
            ]
        ],
    ],
],

// app/middleware.php


// 全局中间件定义文件
return [
    // ......
    \ThinkWorker\middleware\InteractsWithVarDumper::class,
];
shell
 # 此命令一键启动配置文件 `config/worker_*.php` 中 enable 为 true 的服务 
 # 以下命令在linux中权限不足时请自行加sudo
 php think worker start #以调试模式启动服务
 php think worker start -d #以守护进程模式启动服务
 php think worker stop #停止服务
 php think worker restart #重启服务
 php think worker reload #柔性重启服务
 php think worker status #查看服务状态
shell
 # 此命令单独启动 Http 服务 
 # 以下命令在linux中权限不足时请自行加sudo
 php think worker:http start #以调试模式启动服务
 php think worker:http start -d #以守护进程模式启动服务
 php think worker:http stop #停止服务
 php think worker:http restart #重启服务
 php think worker:http reload #柔性重启服务
 php think worker:http status #查看服务状态
shell
 # 此命令单独启动 Queue 队列服务 
 # 以下命令在linux中权限不足时请自行加sudo
 php think worker:queue start #以调试模式启动服务
 php think worker:queue start -d #以守护进程模式启动服务
 php think worker:queue stop #停止服务
 php think worker:queue restart #重启服务
 php think worker:queue reload #柔性重启服务
 php think worker:queue status #查看服务状态
shell
 # 此命令单独启动 crontab 服务 
 # 以下命令在linux中权限不足时请自行加sudo
 php think worker:cron start #以调试模式启动服务
 php think worker:cron start -d #以守护进程模式启动服务
 php think worker:cron stop #停止服务
 php think worker:cron restart #重启服务
 php think worker:cron reload #柔性重启服务
 php think worker:cron status #查看服务状态