PHP code example of cncoders / thinkphp-job

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

    

cncoders / thinkphp-job example snippets



namespace app\job;

use cncoders\job\JobInterfaces;
use think\facade\Log;

class TestJob implements JobInterfaces
{
    public function exec($param = [])
    {
        Log::write(json_encode($param));
        return true;
    }
}



namespace app\sys\controller;

use app\BaseController;
use auth\Auther;
use cncoders\job\JobTrait;

class Auth extends BaseController
{
    use JobTrait;

    /**
     * @param Auther $auther
     * @return \think\response\Json
     */
    public function index(Auther $auther)
    {
        $token = $auther->token([
            'user_id' => '100102',
            'nickname' => 'user昵称'
        ]);

        $this->addJob('test_job', 'TestJob', ['token' => $token]);

        return json([
            'token' => $token
        ]);
    }
}