PHP code example of chester / background-mission

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

    

chester / background-mission example snippets


 Chester\BackgroundMission\Providers\MissionProvider::class

// hello world. 测试10万条记录后台导出 csv 文件
public function helloWorld()
{
    $filename = storage_path('app') . '/' . date('YmdHis') . ".csv";
    $handle = fopen($filename, 'w');
    fwrite($handle, chr(0xEF) . chr(0xBB) . chr(0xBF));

    $cur_page = 0;
    fputcsv($handle, ['num', 'datetime']);
    do {
        $cur_page++;
        fputcsv($handle, [$cur_page, date('Y-m-d H:i:s')]);
        // 模拟10万条记录
        if ($cur_page >= 10000000) {
            break;
        }
    } while (true);
    return $this->response(1, "output target file dir: {$filename}");
}


namespace App;

use Chester\BackgroundMission\Logic;

class TestLogic extends Logic
{
    public function myTest()
    {
        sleep(20);
        return $this->response(1, 'my test');
    }
}

'background_logic' => '\App\TestLogic'

Route::get('bg-test', function () {
    app('chester.bg.queue')->push(['method' => 'myTest']);
});
bash
background-tasks/src/2018_11_14_104840_test.php
markdown
$ php artisan mission:add