我正在努力yii2
。我有一个创建功能,我想每 24 小时后在后台运行一次。
public function actionCreate()
{
$model = new MeterPing();
// CURL code to get results from web-api
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
同样在这个函数中,我将从web-API
. 但我主要关心的是每 24 小时后在后台运行上述功能。
更新 1
根据给出的建议,我创建了一个控制器console\controller
namespace console\controllers;
use yii\console\Controller;
class TestController extends Controller {
public function actionIndex() {
echo "cron service runnning";
}}
现在,为了测试它,我点击了这个链接cmd
并使用以下参数创建了一个运行服务
现在,按照建议,我已经尝试了每一步。该.bat
文件包含
@Echo off
title My Cron Job
:: See title at the top
php E:\xampp\htdocs\inventory-web\yii test
pause
保存文件并将其添加到任务计划程序后。我试图从这个界面运行它。我确实看到一个 cmd 打开并显示消息。
我该怎么做?任何帮助将不胜感激。