Skip to content

[Bug] Temporal PHP SDK doing its own extension check, breaking composer's --ignore-platform-reqs #689

@adepretis

Description

@adepretis

What are you really trying to do?

Installing the Temporal PHP SDK using composer with --ignore-platform-reqs.

Describe the bug

The Temporal PHP SDK does not adhere to common practices for composer installations and is checking grpc availability in the code.

There are plenty of use-cases to run composer install --ignore-platform-reqs which allows installing composer packages without checking for e.g. installed PHP extensions.

A PHP package would typically define its platform requirements in composer.json. Temporal does that too for the correct PHP version and PHP's curl and json extension.

    "require": {
        "php": ">=8.1",
        "ext-curl": "*",
        "ext-json": "*",

What is missing here though is

    "require": {
        "php": ">=8.1",
        "ext-curl": "*",
        "ext-json": "*",
        "ext-grpc": "*",

Instead the grpc availability is check in https://github.com/temporalio/sdk-php/blob/master/src/Client/GRPC/BaseClient.php#L99-L101.

Normally this is not an issue, but in case of Laravel's package discovery the PHP code seems to be executed and fails - wether --ignore-platform-reqs is given or not.

   RuntimeException

  The gRPC extension is required to use Temporal Client.

  at vendor/temporal/sdk/src/Client/GRPC/BaseClient.php:72
     68▕      */
     69▕     public static function create(string $address): static
     70▕     {
     71▕         if (!\extension_loaded('grpc')) {
  ➜  72▕             throw new \RuntimeException('The gRPC extension is required to use Temporal Client.');
     73▕         }
     74▕
     75▕         return new static(static fn(): WorkflowServiceClient => new WorkflowServiceClient(
     76▕             $address,

Also, for some reason, adding temporal/sdk to composer.json doesn't help either:

      "extra": {
          "laravel": {
              "dont-discover": ["temporal/sdk"]
          }
      },

Minimal Reproduction

  • create a Laravel project
  • if not created by Laravel bootstrapping add the following to composer.json
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
  • run composer install --ignore-platform-reqs with no grpc extension installed

Environment/Versions

  • Temporal SDK version: 2.16.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions