-
-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Description
环境
PHP 7.3.26
swoole 4.6.1
hyperf v2.1.1
配置config\autoload\crontab.php
return [
// 是否开启定时任务
'enable' => true,
];config\autoload\server.php
'settings' => [
...
// Task Worker 数量,根据您的服务器配置而配置适当的数量
'task_worker_num' => 1,
// 因为 `Task` 主要处理无法协程化的方法,所以这里推荐设为 `false`,避免协程下出现数据混淆的情况
'task_enable_coroutine' => false,
],
'callbacks' => [
...
// Task callbacks
Event::ON_TASK => [Hyperf\Framework\Bootstrap\TaskCallback::class, 'onTask'],
Event::ON_FINISH => [Hyperf\Framework\Bootstrap\FinishCallback::class, 'onFinish'],
],运行官方文档示例
<?php
declare(strict_types=1);
namespace App\Task;
use Hyperf\Crontab\Annotation\Crontab;
use Hyperf\Di\Annotation\Inject;
/**
* @Crontab(name="LogCleanerTask", rule="*\/5 * * * * *", callback="execute")
*/
class LogCleanerTask
{
/**
* @Inject()
* @var \Hyperf\Contract\StdoutLoggerInterface
*/
private $logger;
public function execute()
{
$this->logger->info(date('Y-m-d H:i:s', time()));
}
}报错
[2021-02-06 16:51:00 *1514.0] ERROR php_swoole_server_rshutdown (ERRNO 503): Fatal error: Uncaught Swoole\Error: Socket#35 has already been bound to another coroutine#20, writing of the same socket in coroutine#21 at the same time is not allowed in /data/wwwroot/hyperf-api/vendor/symfony/console/Output/StreamOutput.php:76
Stack trace:
#0 /data/wwwroot/hyperf-api/vendor/symfony/console/Output/StreamOutput.php(76): fwrite(Resource id #1632, '\e[32m[DEBUG]\e[3...')
#1 /data/wwwroot/hyperf-api/vendor/symfony/console/Output/Output.php(166): Symfony\Component\Console\Output\StreamOutput->doWrite('\e[32m[DEBUG]\e[3...', true)
#2 /data/wwwroot/hyperf-api/vendor/symfony/console/Output/Output.php(132): Symfony\Component\Console\Output\Output->write(Array, true, 1)
#3 /data/wwwroot/hyperf-api/vendor/hyperf/framework/src/Logger/StdoutLogger.php(138): Symfony\Component\Console\Output\Output->writeln('<info>[DEBUG]</...')
#4 /data/wwwroot/hyperf-api/vendor/hyperf/framework/src/Logger/StdoutLogger.php(113): Hyperf\Framework\Logger\StdoutLogger->log('debug', '<info>[DEBUG]</...', Array)
#5 /data/wwwroot/hyperf-ap in /data/wwwroot/hyperf-api/vendor/symfony/console/Output/StreamOutput.php on line 76
[2021-02-06 16:51:00 $1510.0] WARNING check_worker_exit_status: worker#0[pid=1514] abnormal exit, status=255, signal=0关闭crontab则不会报这个错误
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels