FastCGI sent in stderr: “PHP message: PHP Catchable fatal error: Argument 1 passed to must be an in

问题描述:

php调用thrift接口报错

[error] 14178#14178: *1298868 FastCGI sent in stderr: "PHP message: PHP Catchable fatal error:  Argument 1 passed to MonitorOsView\AgentMetricServiceClient::SearchLog() must be an instance of MonitorOsView\BasicSearchLog, array given in Thrift/gen-php/MonitorOsView/AgentMetricService.php on line 1740" while reading response header from upstream, client: , request: "GET /api/"

原因分析:

传递的第一个参数需要是BasicSearchLog的实例,types.php这个文件一般不用它,忽略了它后遇到问题会有点蒙逼


解决方案:

在这里插入图片描述

thrift模板:

struct BasicSearchLog {
  1: required string index,
  2: required i64 startTime,
  3: required i64 endTime,
  4: required string id;  
  5: required string name;     
  6: optional i64 age;  
  7: optional string address;
  8: optional bool isAdmin=false; 
}

Types.php代码(自动生成的文件):

class BasicSearchLog {
 static $_TSPEC;

 public $index = null;

 public $startTime = null;

 public $endTime = null;

 public $size = null;
 
 ....

 public function __construct($vals=null) {
   if (!isset(self::$_TSPEC)) {
     self::$_TSPEC = array(
       1 => array(
         'var' => 'index',
         'type' => TType::STRING,
         ),
       2 => array(
         'var' => 'startTime',
         'type' => TType::I64,
         ),
       3 => array(
         'var' => 'endTime',
         'type' => TType::I64,
         ),
        ......
       );
   }
   if (is_array($vals)) {
     if (isset($vals['index'])) {
       $this->index = $vals['index'];
     }
     if (isset($vals['startTime'])) {
       $this->startTime = $vals['startTime'];
     }
     if (isset($vals['endTime'])) {
       $this->endTime = $vals['endTime'];
     }
     
   .......
   }
 }

直接实例化后传递即可

        $BasicSearchLog = new \MonitorOsView\BasicSearchLog($basicLogSearch);
        $monitorOsViewThrift = new Thrift_MonitorOsView();
        $retData = $monitorOsViewThrift->SearchDistinctLogByField($BasicSearchLog, [], [], []);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值