dpnzf48660 2014-10-28 19:03
浏览 52
已采纳

Gearman工作者无法访问PHP框架

Hi I've installed and configured Gearman. So far it has been great trying out examples, and when I came to the part where I am actually going to use it in my project, that's where my problem began.

I'm using Yii php framework in my project, and I included all my worker files in the main project directory.

ProjectName/workers/worker.php

My workers' function are to insert values in the database given a parameter. So I had to include sql query, and since i'm using Yii, I use the :

Yii::app()->db->createCommand($sql)->execute();

and I encounter the error :

PHP Fatal error:  Class 'Yii' not found in /home/user/lappstack-5.4.34-0/apache2/htdocs/ProjectName/workers/worker.php on line 52

It seems that my CLI PHP cannot find Yii, so I tried doing it old school using PDO :

$db = new PDO('pgsql:db...........'usr','pas');
$stmt = $dbh->prepare($sql);
$stmt->execute();

and I get the error :

PHP Fatal error:  Uncaught exception 'PDOException' with message 'could not find driver' in /home/user/lappstack-5.4.34-0/apache2/htdocs/ProjectName/workers/worker.php:54

So it seems that the worker basically doesn't have a server environment unlike my web application that can access Yii functions and what not. How do resolve this?

  • 写回答

1条回答 默认 最新

  • duanping1632 2014-10-29 05:15
    关注

    How do you spawn your workers? In order to use Yii your workers need to be instantiated with such command: /home/sites/projectName/php yiic command-name

    Please read the documentation on creating commands it is well written: http://www.yiiframework.com/doc/guide/1.1/en/topics.console

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部