dpnzf48660 2014-10-29 03: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 13: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

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

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分