用Yii2的console寫了個腳本,在命令行執行都OK。
放到cron裡面也按時去執行了,但就是執行的效果不對,console腳本執行結果不對。
查看之後的是由於yii腳本的php路徑問題(跟目錄下面的yii)
需要將一下代碼的第一行,php換成你服務器上面的路徑
#!/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('YII_DEBUG') or define('YII_DEBUG', true); defined('YII_ENV') or define('YII_ENV', 'dev'); require(__DIR__ . '/vendor/autoload.php'); require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php'); require(__DIR__ . '/common/config/bootstrap.php'); require(__DIR__ . '/console/config/bootstrap.php'); $config = yii\helpers\ArrayHelper::merge( require(__DIR__ . '/common/config/main.php'), require(__DIR__ . '/common/config/main-local.php'), require(__DIR__ . '/console/config/main.php'), require(__DIR__ . '/console/config/main-local.php') ); $application = new yii\console\Application($config); $exitCode = $application->run(); exit($exitCode);
http://xxxxxx/Linuxjc/1159967.html TechArticle