为了账号安全,请及时绑定邮箱和手机立即绑定

Google Cloud Vision - 解析期间发生 PHP 错误

Google Cloud Vision - 解析期间发生 PHP 错误

PHP
婷婷同学_ 2022-10-09 19:51:53
我正在使用适用于 PHP 的 Vision API 客户端库。这是我的代码:use Google\Cloud\Vision\V1\ImageAnnotatorClient;putenv("GOOGLE_APPLICATION_CREDENTIALS=/json.json");$imageAnnotator = new ImageAnnotatorClient();$fileName = 'textinjpeg.jpg';$image = file_get_contents($fileName);$response = $imageAnnotator->labelDetection($image);$labels = $response->getLabelAnnotations();if ($labels) {    echo("Labels:" . PHP_EOL);    foreach ($labels as $label) {        echo($label->getDescription() . PHP_EOL);    }} else {    echo('No label found' . PHP_EOL);}我收到这个错误:Error occurred during parsing: Fail to push limit. (0)/srv/www/site.ru/htdocs/vendor/google/protobuf/src/Google/Protobuf/Internal/CodedInputStream.php:345#0: Google\Protobuf\Internal\CodedInputStream-&gt;pushLimit(integer)    /srv/www/site.ru/htdocs/vendor/google/protobuf/src/Google/Protobuf/Internal/CodedInputStream.php:368#1: Google\Protobuf\Internal\CodedInputStream-&gt;incrementRecursionDepthAndPushLimit(integer, integer, integer)............#15: Google\Cloud\Vision\V1\ImageAnnotatorClient-&gt;labelDetection(string)/srv/www/site.ru/htdocs/local/php_interface/GoogleCloud.php:41这是异常来自的地方:public function pushLimit($byte_limit){    // Current position relative to the beginning of the stream.    $current_position = $this->current();    $old_limit = $this->current_limit;    // security: byte_limit is possibly evil, so check for negative values    // and overflow.    if ($byte_limit >= 0 &&        $byte_limit <= PHP_INT_MAX - $current_position &&        $byte_limit <= $this->current_limit - $current_position) {        $this->current_limit = $current_position + $byte_limit;        $this->recomputeBufferLimits();    } else {        throw new GPBDecodeException("Fail to push limit.");    }    return $old_limit;}$byte_limit <= $this->current_limit - $current_position是真的我应该增加 current_position 吗?如果我应该,我该怎么做?在服务器或 PHP 配置中更改某些内容?
查看完整描述

3 回答

?
青春有我

TA贡献1784条经验 获得超8个赞

这是一件很疯狂的事情!

论坛中不时出现“无法推送限制”错误。关于问题可能出在哪里,那里给出了各种想法。一个原因可能是源代码通过 Composer 在本地 PC 上编写,然后通过 (S)FTP 传输到服务器。FTP 程序根据文件扩展名决定将数据以 ASCII 格式还是二进制格式保存在服务器上。

在 vendor/google/protobuf/src/Google/Protobuf/ 中,有各种生成的文件具有 .php 扩展名,但实际上是二进制文件!(如果您打开文件,您可以立即看到它,例如:vendor/google/protobuf/src/GPBMetadata/Google/Protobuf/Any.php)在我的案例中,通过二进制文件将这些文件显式传输到服务器的解决方案有效!如果有疑问,请将 Google/protobuf 中的完整模块作为二进制文件传输...


查看完整回答
反对 回复 2022-10-09
?
慕码人8056858

TA贡献1803条经验 获得超6个赞

mbstring.func_overload 为 2 这是错误的原因 更改为 0 并且有效



查看完整回答
反对 回复 2022-10-09
?
暮色呼如

TA贡献1853条经验 获得超9个赞

你提到那$byte_limit <= $this->current_limit - $current_position是真的,所以要么$byte_limit >= 0或要么$byte_limit <= PHP_INT_MAX - $current_position是假的。

如果$byte_limit <= PHP_INT_MAX - $current_position是假的,那么增加$current_position,不会变成真的。如果要调整值,使表达式被评估为真,则需要增加 PHP_INT_MAX 的值

如果$byte_limit >= 0为假,则修改$current_limit不会避免异常。

无论哪种方式,错误似乎都是protobufphp 库的问题,所以我建议您在那里报告问题,而不是尝试直接修改值。


查看完整回答
反对 回复 2022-10-09
  • 3 回答
  • 0 关注
  • 184 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号