Search code examples
phpworkflowtemporaltemporal-workflow

Unable to start Temporal Workflow in PHP


There is this Vue App, which uses PHP as a backend. I am incorporating Temporal PHP SDK for Workflow management. The task is simple:

Create a WorkflowClient, Start the Workflow.

But this app stops at the Creation of the WorkflowClient.

I searched and tried various solutions but there are many examples in Java and GO. I want it in PHP. Below is my PHP function that starts the workflow.

public function delete_vendor() {
        cakelog::write('debug', 'delete_vendor');
        $this->autoRender = false;
        $id = $this->request->data['vendorId'];
        cakelog::write('debug', 'vendorID: ' . $id);
        // Assumes the Temporal server is running locally. Update to point to your Temporal server if not.
        $workflowClient = WorkflowClient::create(ServiceClient::create('localhost:7233'));
        cakelog::write('debug', 'workflowClient: ' . $workflowClient);
        
        // Start a workflow execution. 
        $workflow = $workflowClient->newWorkflowStub(DeleteVendorWorkflowInterface::class);
        cakelog::write('debug', 'Workflow Stub: ' . $workflow);
        $run = $workflowClient->start($workflow, $id);
        cakelog::write('debug', 'Workflow Runs: ' . $run);
    
        echo "Started workflow: " . $run->getExecution()->getID();
    }

WorkflowClient is not being created.
But I have checked these:

Checking Temporal Versiontemporal --version and the output was

temporal version 0.10.7 (server 1.22.2) (ui 2.21.3)

Checking the Availability of port 7233 lsof -i :7233 and the outupt was


COMMAND     PID             USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
temporal 416201 priyanhomeoffice   12u  IPv4 2399201      0t0  TCP localhost:7233 (LISTEN)
temporal 416201 priyanhomeoffice   14u  IPv4 2402310      0t0  TCP localhost:42916->localhost:7233 (ESTABLISHED)
temporal 416201 priyanhomeoffice   15u  IPv4 2401011      0t0  TCP localhost:42922->localhost:7233 (ESTABLISHED)
temporal 416201 priyanhomeoffice   18u  IPv4 2401598      0t0  TCP localhost:7233->localhost:42916 (ESTABLISHED)
temporal 416201 priyanhomeoffice   19u  IPv4 2401599      0t0  TCP localhost:7233->localhost:42922 (ESTABLISHED)
temporal 416201 priyanhomeoffice   20u  IPv4 2402346      0t0  TCP localhost:42934->localhost:7233 (ESTABLISHED)
temporal 416201 priyanhomeoffice   22u  IPv4 2401602      0t0  TCP localhost:42924->localhost:7233 (ESTABLISHED)
temporal 416201 priyanhomeoffice   23u  IPv4 2402314      0t0  TCP localhost:7233->localhost:42924 (ESTABLISHED)
temporal 416201 priyanhomeoffice   41u  IPv4 2401664      0t0  TCP localhost:42940->localhost:7233 (ESTABLISHED)
temporal 416201 priyanhomeoffice   42u  IPv4 2401092      0t0  TCP localhost:7233->localhost:42940 (ESTABLISHED)
temporal 416201 priyanhomeoffice   43u  IPv4 2401093      0t0  TCP localhost:7233->localhost:42934 (ESTABLISHED)
temporal 416201 priyanhomeoffice   44u  IPv4 2401095      0t0  TCP localhost:42946->localhost:7233 (ESTABLISHED)
temporal 416201 priyanhomeoffice   45u  IPv4 2403339      0t0  TCP localhost:42962->localhost:7233 (ESTABLISHED)
temporal 416201 priyanhomeoffice   46u  IPv4 2402347      0t0  TCP localhost:7233->localhost:42946 (ESTABLISHED)
temporal 416201 priyanhomeoffice   47u  IPv4 2402348      0t0  TCP localhost:7233->localhost:42962 (ESTABLISHED)
temporal 416201 priyanhomeoffice   48u  IPv4 2401096      0t0  TCP localhost:42972->localhost:7233 (ESTABLISHED)
temporal 416201 priyanhomeoffice   49u  IPv4 2402350      0t0  TCP localhost:7233->localhost:42972 (ESTABLISHED)
temporal 416201 priyanhomeoffice   50u  IPv4 2403340      0t0  TCP localhost:42984->localhost:7233 (ESTABLISHED)
temporal 416201 priyanhomeoffice   51u  IPv4 2401097      0t0  TCP localhost:7233->localhost:42984 (ESTABLISHED)

Then Checking if the temporal server is running or not tctl --address localhost:7233 admin cluster describe and the output was


{
  "supportedClients": {
    "temporal-cli": "\u003c2.0.0",
    "temporal-go": "\u003c2.0.0",
    "temporal-java": "\u003c2.0.0",
    "temporal-php": "\u003c2.0.0",
    "temporal-server": "\u003c2.0.0",
    "temporal-typescript": "\u003c2.0.0",
    "temporal-ui": "\u003c3.0.0"
  },
  "serverVersion": "1.22.2",
  "membershipInfo": {
    "currentHost": {
      "identity": "127.0.0.1:7233"
    },
    "reachableMembers": [
      "127.0.0.1:37583",
      "127.0.0.1:40529",
      "127.0.0.1:46721",
      "127.0.0.1:36103"
    ],
    "rings": [
      {
        "role": "frontend",
        "memberCount": 1,
        "members": [
          {
            "identity": "127.0.0.1:7233"
          }
        ]
      },
      {
        "role": "history",
        "memberCount": 1,
        "members": [
          {
            "identity": "127.0.0.1:45175"
          }
        ]
      },
      {
        "role": "matching",
        "memberCount": 1,
        "members": [
          {
            "identity": "127.0.0.1:46139"
          }
        ]
      },
      {
        "role": "worker",
        "memberCount": 1,
        "members": [
          {
            "identity": "127.0.0.1:39389"
          }
        ]
      }
    ]
  },
  "clusterId": "3a8d0818-8247-4b8c-a86b-f6c2f98437ab",
  "clusterName": "active",
  "historyShardCount": 1,
  "persistenceStore": "sqlite",
  "visibilityStore": "sqlite",
  "versionInfo": {
    "current": {
      "version": "1.22.2",
      "releaseTime": "2023-11-13T19:00:00Z"
    },
    "recommended": {
      "version": "1.22.3",
      "releaseTime": "2023-12-08T02:00:00Z"
    },
    "alerts": [
      {
        "message": "🪐 A new release is available!",
        "severity": "Low"
      }
    ],
    "lastUpdateTime": "2023-12-22T07:19:23.866918702Z"
  },
  "failoverVersionIncrement": "10",
  "initialFailoverVersion": "1"
}

The Temporal Web UI opens but the WorkflowClient is not being created. What may be the problem? Thanks in advance :)


Solution

  • There was this dependency issue of GRPC. Once I installed it. It worked like a normal execution. However, I was still struggling to adopt this framework. I hope the community and the documentation were better in a way that a Junior dev or intern could use and understand it.