在Laravel中使用grpc,“未找到类'Grpc \ ChannelCredentials'". [英] Using grpc in Laravel, "Class 'Grpc\ChannelCredentials' not found."

查看:964
本文介绍了在Laravel中使用grpc,“未找到类'Grpc \ ChannelCredentials'".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Laravel项目中使用grpc.

I am trying to use grpc in a Laravel project.

这是我的composer.json文件的一部分:

This is a part of my composer.json file:

"require": {
    ...
    "datto/protobuf-php": "dev-master",
    "google/auth": "^0.7.0",
    "grpc/grpc": "dev-release-0_13",
    ...
}

我已经从我的原始文件中生成了一个php文件.它放置在app/services/中,并包含在composer.json autoload.files部分中.我已经运行composer install没问题.

I have generated a php file from my proto file. It is placed in app/services/ and included in the composer.json autoload.files section. I have run composer install without issues.

我已经创建了测试路径.它具有以下代码:

I have created a route for testing. It has the following code:

$client = new vat_service\VatServiceClient('localhost:50051', [
    'credentials' => Grpc\ChannelCredentials::createInsecure()
]);

但是当我访问路线时,我会收到响应Class 'Grpc\ChannelCredentials' not found..

But I receive the response Class 'Grpc\ChannelCredentials' not found. when I visit the route.

Laravel应用程序在Homestead流浪者盒子中运行.

The Laravel app is running in a Homestead vagrant box.

我不知道如何进行.我是否缺少依赖关系?我想念安装什么东西吗?

I don't know how to proceed. Am I missing a dependency? Did I miss to install something?

推荐答案

我已经解决了问题,但是我不确定以下哪个步骤是解决方案.

I have solved the problem, but I am not sure which of the below steps was the solution.

我尝试过的事情:

  • 我在Homestead盒(sudo pecl install grpc-beta)中安装了grpc-beta.
  • 我从"grpc/grpc": "dev-release-0_13"更新到了"grpc/grpc": "^0.15.0".
  • 我在composer.json中添加了一个存储库:

  • I installed grpc-beta in the Homestead box (sudo pecl install grpc-beta).
  • I updated from "grpc/grpc": "dev-release-0_13" to "grpc/grpc": "^0.15.0".
  • I added a repository to composer.json:

"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/stanley-cheung/Protobuf-PHP"
    }
],

  • 我在Homestead盒子内重新启动了NGINX
  • 我用composer self-update
  • 更新了作曲家

  • I restarted NGINX inside the Homestead box
  • I updated composer with composer self-update
  • 我将此添加为答案.请告知它是否更适合作为开头问题的编辑或注释.

    I added this as an answer. Please advise if it would be better suited as an edit to the opening question or as a comment.

    另外,了解解决方案是很有趣的.

    Also, it would be interesting to learn what the solution was.

    这篇关于在Laravel中使用grpc,“未找到类'Grpc \ ChannelCredentials'".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆