Hyperf 之 定时任务
https://www.hyperf.wiki/#/zh-cn/crontab
<?php
namespace App\Task;
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\Crontab\Annotation\Crontab;
use Hyperf\Di\Annotation\Inject;
use Hyperf\Guzzle\CoroutineHandler;
/**
* @Crontab(name="Foo", rule="*\/30 * * * *", callback="execute", memo="这是一个示例的定时任务")
*/
class FooTask
{
/**
* @Inject()
* @var \Hyperf\Contract\StdoutLoggerInterface
*/
private $logger;
public function execute()
{
$client = new Client([
'handler' => HandlerStack::create(new CoroutineHandler()),
'timeout' => 20,
]);
$response = $client->get("http://122.51.154.126:8003/?is_upd=2&limit=100");
$respBody = $response->getBody()->getContents();
var_dump($respBody);
return $respBody;
// $this->logger->info(date('Y-m-d H:i:s', time()));
}
}
