Function App for custom handler PHP

Abhay Vijay Pai 0 Reputation points
2024-02-14T11:20:57.4466667+00:00

I am planning to create new function app using custom handler supporting php language for the app which will further communicate with sharepoint using HTTPTrigger and since we have few to none official documentation for the same looking for further suggestion here if anyone has tried before.

Facing following issues at the moment while running func start locally:

  1. [2024-02-14T10:22:13.916Z] Failed to start Worker Channel. Process fileName: <path>/worker.php
  2. [2024-02-14T10:22:13.916Z] System.Diagnostics.Process: An error occurred trying to start process <path>/worker.php Permission denied
  3. Endpoint is shared by func start command http://localhost:7071/api/HttpTrigger but it is not working to further test code locally

Facing following issues at the moment after publishing func azure functionapp publish $functionName:

  1. Using Test/Run in browser function is returning 504 Gateway timeout with "GET" request
  2. Message is "Our services aren't available right now"

Following is the structure of code:

Screenshot 2024-02-14 at 4.45.19 PM

Following is the host.json file:

Screenshot 2024-02-14 at 4.47.00 PM

High level steps followed are as follows:

  1. Created function app with custom handler using linux consumption
  2. Created httptrigger for the same
  3. Sample code is attached here https://github.com/AbhayPai/azure-function-app-php/

Few suggestion i have looked into are old and listing them down here:

  1. https://www.lieben.nu/liebensraum/2017/08/parsing-a-get-request-in-php-with-an-azure-function/
  2. https://learn.microsoft.com/en-us/azure/azure-functions/functions-custom-handlers
  3. https://github.com/anthonychu/azure-functions-php-worker-sample

Looking for some working sample or possibilities if there is any limitation in function app for custom handling php

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MayankBargali-MSFT 70,936 Reputation points Moderator
    2024-02-14T14:28:17.33+00:00

    @Abhay Vijay Pai I have tested your code and changed the host.json Microsoft.Azure.Functions.ExtensionBundle version to [1.*, 4.0.0) and defaultExecutablePath to php. For your reference sharing the same

    {
    	"version": "2.0",
    	"extensionBundle": {
    		"id": "Microsoft.Azure.Functions.ExtensionBundle",
    		"version": "[1.*, 4.0.0)"
    	},
    	"customHandler": {
    		"description": {
          "defaultExecutablePath": "php",
          "arguments": [
            "-S",
            "0.0.0.0:%FUNCTIONS_CUSTOMHANDLER_PORT%",
            "worker.php"
          ]
        },
        "enableForwardingHttpRequest": false
      },
      "logging": {
        "logLevel": {
          "Function.HttpTrigger.User": "Information",
          "default": "Warning"
        },
        "applicationInsights": {
          "samplingSettings": {
            "isEnabled": true
          }
        }
      }
    }
    
    
    

    In your index.php file I have changed the below to make it simple and I have tested the same after modifying the above and below changes.

    <?php
        function run(FunctionContext $context) {
            $req = $context->inputs['req'];
            //$context->log->information(json_encode($req));
            $context->log->information('Http trigger invoked');
    
            $query = 'This is test response';
    
            return [
                'body' => $query,
                'headers' => [
                    'Content-type' => 'text/plain'
                ]
            ];
        }
    ?>
    
    
    

    Note: Your most of the error will be solved if you update the host.json with the right value and make sure to run your visual studio code in administrative mode. You also need to make sure that you have PHP installed and the environment path is correctly reflected to your path where your php folder exists and php folder\ext User's image User's image


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.