herokuの環境でPHPのアプリケーションからfirestoreに書き込みを行おうかと思ったのですが、どうやらherokun環境だとgRPCが使えないようで、色々と詰まったので調べたことをまとめました。(結構前に対応した内容なので、怪しいところがあるが)
gRPCってなんぞやという方はgRPCって何?をご覧ください。
やろうとしたこと
googleapis/google-cloud-php-firestore を使用して、PHPで作成したアプリケーションからfirestoreへ何かをする(忘れた)コードを書いていました。
gRPC for PHPのインストールが必要なため、ドキュメント通りgRPC 拡張機能のインストールを行い、ローカルではfirestoreの操作が可能なことは確認ができました。
このコードを使用して、herokuからfirestoreの操作を行えるようにしようと思いました。
herokuビルド時のエラー
herokuの環境には拡張機能をインストールしていないので、エラーになるのはわかっていましたが、とりあえずpushしてみてビルドさせたところ、下記のエラーになりました。
google/cloud-firestore v1.11.0 requires ext-grpc * -> no matching package found
ext-grpc
が必要らしい。
-----> PHP app detected
-----> Bootstrapping...
-----> Installing platform packages...
! WARNING: A requested extension is not available
! ERROR: Failed to install system packages!
!
! Your platform requirements (for runtimes and extensions) could
! not be resolved to an installable set of dependencies, or a
! platform package repository was unreachable.
!
! This usually means that you (or packages you are using) depend
! on a combination of PHP versions and/or extensions that are
! currently not available on Heroku.
!
! The following is the full output from the installation attempt:
!
! > Loading repositories with available runtimes and extensions
! > Updating dependencies
! > Your requirements could not be resolved to an installable set of packages.
! >
! > Problem 1
! > - Installation request for google/cloud-firestore v1.11.0 -> satisfiable by google/cloud-firestore[v1.11.0].
! > - google/cloud-firestore v1.11.0 requires ext-grpc * -> no matching package found.
! >
!
! For reference, the following runtimes are currently available:
!
! PHP: 7.4.2, 7.3.14, 7.3.13, 7.2.27, 7.2.26, 7.1.33
! HHVM:
!
! Please verify that all requirements for runtime versions in
! 'composer.lock' are compatible with the list above, and ensure
! all required extensions are available for the desired runtimes.
!
! When choosing a PHP runtimes and extensions, please also ensure
! they are available on your app's stack (heroku-18), and select
! a different stack if needed after consulting the article below.
!
! Be advised that the heroku-18 stack you're currently using only
! supports PHP version 7.1 and later.
!
! For a list of supported runtimes & extensions on Heroku, please
! refer to: https://devcenter.heroku.com/articles/php-support
!
! REMINDER: the following warnings were emitted during the build;
! check the details above, as they may be related to this error:
! - A requested extension is not available
! Push rejected, failed to compile PHP app.
! Push failed
herokuのサポート状況
Heroku PHP Supportを確認しても ext-grpc
の記載はなく、stack overflowでも似たような質問があり、そもそもHTTP/2がサポートされてないとのこと。(gRPCはHTTP/2を利用している)
Heroku does not support HTTP 2. On the other hand, GRPC uses a http/2 based transport. I think that's why you can connect it locally but not from Heroku.
念のため、HTTP versions supportedを確認したところ、下記の記載があったため、サポートされていないことが確認できました。
SPDY and HTTP/2 are not supported at this point.