gearman

  1. 作者QQ:67065435 QQ群:821635552

  2. 本站内容全部为作者原创,转载请注明出处!

基础用法

  1. client代码 src/CommandBundle/Command/ClientCommand.php

    <?php
    $works = [
        123,
        124,
        125
    ];
    foreach ($works as $work) {
        $client = new \GearmanClient();
        $client->addServer('127.0.0.1', 4730);
        $client->doBackground("work", $work);
    }
    
  2. worker代码 src/CommandBundle/Command/WorkerCommand.php

    <?php
    $worker = new \GearmanWorker();
    $worker->addServer('127.0.0.1', 4730);
    $worker->addFunction("work", "doWork");
    while ($worker->work()) {
        if ($worker->returnCode() != GEARMAN_SUCCESS) {
            break;
        }
    }
    
    function doWork($job)
    {
        $parameter = $job->workload();
        echo $parameter . PHP_EOL;
    }
    

任务管理

  1. 安装gearman管理包

    composer require brianlmoon/net_gearman
    # 或者修改
    "require": {
        "brianlmoon/net_gearman": "dev-master"
    }
    composer update
    
  2. 编辑代码

    <?php
    
    use Net_Gearman_Manager;
    
    $gearman_manager = new Net_Gearman_Manager('127.0.0.1');
    $status = $gearman_manager->status();
    $gearman_manager->disconnect();
    unset($gearman_manager);
    print_r($status);
    
Copyright © 豆包嘿嘿~ 2012-∞ 冀ICP备17033181号 all right reserved,powered by Gitbook修订: 2020-08-19 14:05:41

results matching ""

    No results matching ""