2
votes

Recently investigating the use of Azure Functions.

Assume you configure a PHP Azure Function with one input, triggered by Azure Message Queue, and an output to another Azure Message Queue.

While trigger works, message is received and code executes flawlessly, i've been unable to identify a means of passing an output which is subsequently loaded into the Output message queue.

I've tried a series of;

    return $variable;
    $variable = $OutputVariableName;
    putenv("OutputVariableName=$OutputVariableName");
    $return = $OutputVariableName; //assuming you've configured this in output settings

Nothing seems to result in the output being dumped into the configured Azure Message Queue.

Thoughts? Cognizant that Azure Functions with PHP is experimental.

Cheers,

T

1

1 Answers

2
votes

You could use file_put_contents function to pass an output into the Output message queue.

run.php

<?php

  $inputMessage = file_get_contents(getenv('inputMessage'));
  $inputMessage = rtrim($inputMessage, "\n\r");
  fwrite(STDOUT, "PHP script processed queue message '$inputMessage'");

  file_put_contents(getenv('outputQueueItem'), $inputMessage);
?>

function.json

{
  "bindings": [
    {
      "name": "inputMessage",
      "type": "queueTrigger",
      "direction": "in",
      "queueName": "samples-php",
      "connection": "aaronchstorage_STORAGE"
    },
    {
      "type": "queue",
      "name": "outputQueueItem",
      "queueName": "outqueue",
      "connection": "aaronchstorage_STORAGE",
      "direction": "out"
    }
  ],
  "disabled": false
}