PHP code example of kukewang / hyperf_xxl_job

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

    

kukewang / hyperf_xxl_job example snippets


   return [
       // 是否启用 xxl_job
       'enable' => env('XXL_JOB_ENABLE', true),
       // XXL-JOB 服务端地址
       'admin_address' => env('XXL_JOB_ADMIN_ADDRESS', 'http://127.0.0.1:8080/xxl-job-admin'),
       // 对应的 AppName,xxl-job 创建的执行器 appName
       'app_name' => env('XXL_JOB_APP_NAME', 'xxl-job-demo'),
       // 访问凭证,执行器的访问凭证,如果配置,必填
       'access_token' => env('XXL_JOB_ACCESS_TOKEN', ''),
       // 执行器心跳间隔(秒)
       'heartbeat' => env('XXL_JOB_HEARTBEAT', 30),
       // 执行器 HTTP Server 相关配置
       'executor_server' => [
           // HTTP Server 路由前缀
           'prefix_url' => env('XXL_JOB_EXECUTOR_PREFIX_URL', 'php-xxl-job')
       ],
       'guzzle_config' => [
           'headers' => [
               'charset' => 'UTF-8',
           ],
           'timeout' => 10,
       ],
       'file_logger' => [
           'dir' => BASE_PATH . '/runtime/xxl_job/logs/',
       ],
   ];
   



declare(strict_types=1);


namespace App\Command;

use Hyperf\XxlJob\Annotation\XxlJob;
use Hyperf\XxlJob\Handler\AbstractJobHandler;
use Hyperf\XxlJob\Requests\RunRequest;

/**
 * @XxlJob(jobHandler="testJobHandler",init="init",destroy="destroy")
 */
class TestCommand extends AbstractJobHandler
{
    public function init()
    {
        var_dump('init');
    }
    
    public function execute(RunRequest $request): void
    {
        var_dump(1);
    }
    
    public function destroy()
    {
        var_dump('destroy');
    }
}