yii2 cron 给出 "PDO not found" 的错误
yii2 cron giving error of "PDO not found"
我运行在yii2中应用得很好。我创建了一个命令控制器 /commands/TestController
<?php
namespace app\commands;
use app\models\UserProfile;
use yii\console\Controller;
use app\controllers\AppController;
/**
* Test controller
*/
class TestController extends Controller
{
public function actionIndex()
{
echo "cron service running";
}
public function actionSendBirthdaySms()
{
$userProfile = UserProfile::find()
->where('MONTH(dob) = MONTH(DATE(NOW()))')
->andWhere('DAY(dob) = DAY(NOW()) ')
->with('user')
->asArray()
->all();
foreach($userProfile as $item){
$birthdayMessage = "Happy Birthday " . $item['user']['username'];
//to send sms
$this->_send_cron_sms($item['mobile'], $birthdayMessage);
}
}
我这里有两个功能。当我调用 php /home/user/public_html/yii test/index
时,它会通过命令行和 cron 给出正确的输出。
但是当我 运行 php /home/user/public_html/yii test/send-birthday-sms
时,它在 ssh 环境中使用命令行运行正常,我正在接收短信。但在 cron 中给出错误。这是我在电子邮件中收到的内容:
Status: 500 Internal Server Error
X-Powered-By: PHP/5.4.39
Content-type: text/html
PHP Fatal Error 'yii\base\ErrorException' with message 'Class 'PDO' not found'
in /home/user/public_html/vendor/yiisoft/yii2/db/Connection.php:609
Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleFatalError()
#1 {main}
我也尝试过查询生成器,但它也没有帮助我。
我已经通过在 php.ini 文件中添加这两个扩展名解决了这个问题
extension=pdo.dll
extension=pdo_mysql.dll
我已经在 Yii forum
中问过同样的问题
我运行在yii2中应用得很好。我创建了一个命令控制器 /commands/TestController
<?php
namespace app\commands;
use app\models\UserProfile;
use yii\console\Controller;
use app\controllers\AppController;
/**
* Test controller
*/
class TestController extends Controller
{
public function actionIndex()
{
echo "cron service running";
}
public function actionSendBirthdaySms()
{
$userProfile = UserProfile::find()
->where('MONTH(dob) = MONTH(DATE(NOW()))')
->andWhere('DAY(dob) = DAY(NOW()) ')
->with('user')
->asArray()
->all();
foreach($userProfile as $item){
$birthdayMessage = "Happy Birthday " . $item['user']['username'];
//to send sms
$this->_send_cron_sms($item['mobile'], $birthdayMessage);
}
}
我这里有两个功能。当我调用 php /home/user/public_html/yii test/index
时,它会通过命令行和 cron 给出正确的输出。
但是当我 运行 php /home/user/public_html/yii test/send-birthday-sms
时,它在 ssh 环境中使用命令行运行正常,我正在接收短信。但在 cron 中给出错误。这是我在电子邮件中收到的内容:
Status: 500 Internal Server Error
X-Powered-By: PHP/5.4.39
Content-type: text/html
PHP Fatal Error 'yii\base\ErrorException' with message 'Class 'PDO' not found'
in /home/user/public_html/vendor/yiisoft/yii2/db/Connection.php:609
Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleFatalError()
#1 {main}
我也尝试过查询生成器,但它也没有帮助我。
我已经通过在 php.ini 文件中添加这两个扩展名解决了这个问题
extension=pdo.dll
extension=pdo_mysql.dll
我已经在 Yii forum
中问过同样的问题