Google Cloud Vision - PHP Ошибка при разборе - PullRequest
1 голос
/ 25 февраля 2020

Я использую клиентскую библиотеку Vision API для PHP. Это мой код:

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 true

Должен ли я увеличить current_position? И если я должен, как я могу это сделать? Изменить что-нибудь на сервере или в PHP config?

Ответы [ 2 ]

0 голосов
/ 29 февраля 2020

mbstring.func_overload было 2 Это было причиной ошибки Изменилось на 0, и это сработало

0 голосов
/ 27 февраля 2020

Вы упомянули, что $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 не сделает его истинным. Если вы хотите настроить значения, чтобы выражение оценивалось как true, вам нужно увеличить значение PHP_INT_MAX вместо .

Если $byte_limit >= 0 равно false, то измените $current_limit не избежит исключения.

В любом случае, похоже, что ошибка связана с библиотекой protobuf php, поэтому я рекомендую сообщить о проблеме там , а не пытаться изменить значения напрямую.

...