PHP code example of busyphp / swoole

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

    

busyphp / swoole example snippets



return [
    // 此处省略...

    // 队列配置
    'queue'      => [
        'enable'  => false,
        'workers' => [
            // 队列名称 => [队列配置]
            'default' => [
                // 设置使用哪个队列连接器,默认依据 `config/queue.php` 中的 `default` 确定
                'connection' => '',
                
                // 启动几个worker并行执行
                'number'     => 1,
                
                // 如果本次任务执行抛出异常且任务未被删除时,设置其下次执行前延迟多少秒
                'delay'      => 0,
                
                // 如果队列中无任务,则多长时间后重新检查
                'sleep'      => 3,
                
                // 如果任务已经超过尝试次数上限,0为不限,则触发当前任务类下的failed()方法
                'tries'      => 0,
                
                // 进程的允许执行的最长时间,以秒为单位
                'timeout'    => 60,
            ],
            
            // 更多队列配置
        ],
    ],

    // 此处省略...
];

return [
    // 此处省略...

    // 定时任务配置
    'timer'      => [
        'enable'  => true,
        'workers' => [
            // 计时器类名,必须实现 \BusyPHP\swoole\contract\timer\TimerInterface 接口
            TimerTask::class
        ],
    ],

    // 此处省略...
];


class TimerTask implements \BusyPHP\swoole\contract\timer\TimerInterface {
    
}
shell script
php think swoole
shell script
php think swoole stop
shell script
php think swoole restart