thinkphp5.1使用workerman做定时器cpu爆满

浏览:1445 发布日期:2020/07/21 分类:求助交流
安装网上教程 使用Workerman 做了个定时器 在window10 上运行没有问题 cpu内存都不高 今天上线到linux上 报错 又按照https://blog.csdn.net/jartins/article/details/86743541 方式修改
使用 php server.php start -d 启动失败
报错 Undefined index: app_path
使用php think worker:server 启动成功
定时器也执行成功了
但是不一会cpu直接爆满了 有哪位大佬知道是什么原因吗 是有禁用函数没有启动吗

<?php
namespace app\push\controller;
use Workerman\Lib\Timer;

use app\admin\controller\Weibo;
class MyTimer{
protected $timer_time = 1;
public function add_timer(){
Timer::add($this->timer_time, array($this, 'index'), array(), true);
}
//执行方法
public function index(){
$ti = cache('weibods');
foreach ($ti as $key => $value) {
$tim[$key]=mktime($value['htime'],$value['itime'],$value['stime'],date('m'),date('d'),date('Y'));
}
$time = time();//现在时间戳
foreach ($tim as $ki => $val) {
if($time === $val){
$wb = new weibo();
$wb->tophots();
$site = "\n".date('Y-m-d H:i:s',time());
file_put_contents('shiq.txt', $site.'执行了一次定时任务。\n',FILE_APPEND | LOCK_EX);
}
}
}
}
最佳答案
评论( 相关
后面还有条评论,点击查看>>