Home  >  Article  >  PHP Framework  >  How to solve the problem of unsuccessful scheduled tasks in yii2

How to solve the problem of unsuccessful scheduled tasks in yii2

angryTom
angryTomOriginal
2019-11-06 16:18:581915browse

How to solve the problem of unsuccessful scheduled tasks in yii2

How to solve the problem if the yii2 scheduled task is unsuccessful

I wrote a script using the Yii2 console and executed it on the command line All OK. It was put into cron and executed on time, but the execution effect was wrong, and the console script execution result was wrong.

After checking, it is due to the php path problem of the yii script (yii under the root directory)

You need to replace the first line of the following code, php, with the path on your server

#!/usr/bin/env php
<?php
/**
 * Yii console bootstrap file.
 *
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */defined(&#39;YII_DEBUG&#39;) or define(&#39;YII_DEBUG&#39;, true);
defined(&#39;YII_ENV&#39;) or define(&#39;YII_ENV&#39;, &#39;dev&#39;);
require(__DIR__ . &#39;/vendor/autoload.php&#39;);
require(__DIR__ . &#39;/vendor/yiisoft/yii2/Yii.php&#39;);
require(__DIR__ . &#39;/common/config/bootstrap.php&#39;);
require(__DIR__ . &#39;/console/config/bootstrap.php&#39;);
$config = yii\helpers\ArrayHelper::merge(
    require(__DIR__ . &#39;/common/config/main.php&#39;),
    require(__DIR__ . &#39;/common/config/main-local.php&#39;),
    require(__DIR__ . &#39;/console/config/main.php&#39;),
    require(__DIR__ . &#39;/console/config/main-local.php&#39;)
);
$application = new yii\console\Application($config);
$exitCode = $application->run();
exit($exitCode);

Or add a soft connection to the PHP executable file on the server

ln -s /usr/local/php/bin/php /usr/local/bin/php

ln - s The absolute path where the current file absolute path is to be placed

Recommended: "YII Tutorial"

The above is the detailed content of How to solve the problem of unsuccessful scheduled tasks in yii2. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn