我正在使用適用于 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->pushLimit(integer) /srv/www/site.ru/htdocs/vendor/google/protobuf/src/Google/Protobuf/Internal/CodedInputStream.php:368#1: Google\Protobuf\Internal\CodedInputStream->incrementRecursionDepthAndPushLimit(integer, integer, integer)............#15: Google\Cloud\Vision\V1\ImageAnnotatorClient->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貢獻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
不會避免異常。
無論哪種方式,錯誤似乎都是protobuf
php 庫的問題,所以我建議您在那里報告問題,而不是嘗試直接修改值。
- 3 回答
- 0 關注
- 220 瀏覽
添加回答
舉報
0/150
提交
取消