承接 videlalvaro/azserverless 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

videlalvaro/azserverless

Composer 安装命令:

composer require videlalvaro/azserverless

包简介

"PHP Custom Handler for Azure Functions"

README 文档

README

This projects provides a PHP Custom Handler for Azure Functions.

Installation

In your composer.json add the following dependency:

"require": {
        "videlalvaro/azserverless": "*"
}

Then run:

composer update

Then start an Azure Functions project. In your host.json add the following:

"customHandler": {
    "description": {
        "defaultExecutablePath": "php",
        "arguments": [
            "-S",
            "0.0.0.0:%FUNCTIONS_CUSTOMHANDLER_PORT%",
            "vendor/videlalvaro/azserverless/bin/serverless.php"
        ]
    },
    "enableForwardingHttpRequest": false
},

See host.sample.json for an example of how this file should look like.

Finally, make copy the file local.settings.sample.json into your project and call it local.settings.json. Adapt the contents to include your connection strings in the AzureWebJobsStorage field.

Usage

In your Azure Functions project you will have one folder per serverless function.

To create a function called HttpTrigger, create a folder with the same name, then inside add two files: function.json and index.php. Here's their content:

{
  "disabled": false,
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "$return"
    }
  ]
}

And the corresponding index.php file:

<?php
use Azserverless\Context\FunctionContext;

function run(FunctionContext $context) {

    $req = $context->inputs['req'];

    $context->log->info('Http trigger invoked');

    $query = json_decode($req['Query'], true);

    if (array_key_exists('name', $query)) {
        $message = 'Hello ' . $query['name'] . '!';
    } else {
        $message = 'Please pass a name in the query string';
    }

    return [
        'body' => $message,
        'headers' => [
            'Content-type' => 'text/plain'
        ]
    ];
}
?>

As you can see functions are provided with a FunctionContext object where they can access request data, and also log information to the console.

To learn more about the details of serverless on Azure, take a look at the Azure Functions documentation.

Deployment

Follow the instructions here to enable PHP 7.4 & make sure composer is run while deploying your function app to Azure: Configure a PHP app for Azure App Service

When the options for Azure CLI require a --name option, provide your Azure Functions app name.

统计信息

  • 总下载量: 2.31k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 18
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 18
  • Watchers: 1
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-11-17