Skip to content

Latest commit

 

History

History
73 lines (54 loc) · 2.05 KB

README.md

File metadata and controls

73 lines (54 loc) · 2.05 KB

Azure Function with PHP

This is a sample function just for testing. PHP is a language that is in experimental mode for now. There is not support for this right now.

Getting Started

You can use this repository to deploy to an Azure Function.

Prerequisites

You need to create the Azure Function first in portal.

This demo is designed for hosting a function inside App Service Plan because the host.json file has not limit for timeout. For Consumption Plan you will have 5 mins by default, you can increase it from 1 second to 10 minutes. You need to add this value in host.json file.

{
    "functionTimeout" : "00:10:00"
}

Printing data in console

For printing variables in console, some examples:

echo "Printing in console with echo \r\n";

fwrite function

fwrite(STDOUT, "Printing in console with fwrite \r\n");

using print_r

print_r("Printing in console with print_r \r\n");

Getting data from Environment variables

For Azure Functions you can get environment the data using these variables:

  • REQ_ORIGINAL_URL
  • REQ_METHOD
  • REQ_QUERY
  • REQ_QUERY_
  • REQ_HEADERS_
  • REQ_PARAMS_
    $req_original_url = getenv('REQ_ORIGINAL_URL');
    $id  = getenv('REQ_PARAMS_id');

Route params

I have added a route inside function.json

    "route": "users/{id:int?}",

This demo is just for GET method, so I can request my function like this: [https://{azurefunctionname}.azurewebsites.net/api/users/{id}?code=/{somerandomcode}&param1=value&param2=value]

Some useful references