【发布时间】:2019-01-24 16:12:45
【问题描述】:
我正在学习grpc,但是发现了一些奇怪的问题。
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: order.proto
namespace Order;
use Google\Protobuf\Internal\GPBUtil;
class Test extends \Google\Protobuf\Internal\Message
{
private $student_id = '';
public function __construct($data = NULL)
{
echo 'test message';
exit;
\GPBMetadata\Order::initOnce();
parent::__construct($data);
}
/**
* Generated from protobuf field <code>string student_id = 1;</code>
*
* @return string
*/
public function getStudentId()
{
return $this->student_id;
}
/**
* Generated from protobuf field <code>string student_id = 1;</code>
*
* @param string $var
* @return $this
*/
public function setStudentId($var)
{
GPBUtil::checkString($var, True);
$this->student_id = $var;
return $this;
}
}
require __DIR__ . '/vendor/autoload.php';
$test = new \Order\Test();
当我执行上面的代码时,我无法得到‘测试消息’;
但是,当我从“测试”类中删除“扩展”时,我可以得到它。
它有什么问题?一些代码在__construct 之前运行?
在nginx/error.log看到如下错误:
74988#0:*380 kevent() 在从上游读取响应标头时报告关闭连接(54:对等方重置连接),客户端:127.0.0.1,服务器:local.grpc.develop,请求:“GET /HTTP/1.1”,上游:“fastcgi://127.0.0.1:9000”,主机:“local.grpc.develop”
在 cli 中运行时我得到了[1] 37548 segmentation fault。
【问题讨论】:
-
你确定你配置你的开发环境来显示所有发生在 php 中的错误吗? (我的意思是
error_reporting(-1);) -
您的构造可能会抛出您没有看到的错误。
-
是的。
error_reporting = E_ALL在 php.ini 中。而我刚刚添加了error_reporting(-1);,同样的错误 -
我把代码放在
try catch,还是得到502 bad gateway -
将您的代码发布为纯文本,而不是图像。有关代码格式化帮助,请参阅 formatting。