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 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改
  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?