Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Functions with PHP

I'm trying out Azure Functions using PHP. Getting the request information is not working for me.

I've not been able to find any documentation at all with the information of how to use Azure Functions with PHP code.

According to the only couple of examples, it seems that in order to retrieve the input information you need to first get the content of the req variable (or whatever name you assign in the function configuration). That has the path of the file containing the request information (in theory).

$input_path = getenv('req');

So far, if I check the content of it, I get something like this:

D:\local\Temp\Functions\Binding\e2b6e195-02f7-481b-a279-eef6f82bc7b4\req

If I check if the file exists it says true, but the file size is 0.

Do anyone knows what to do here? Anyone with an example? Does anyone know where the documentation is?

Thanks

like image 717
Nestor Mata Cuthbert Avatar asked Mar 30 '17 16:03

Nestor Mata Cuthbert


People also ask

Can PHP be used with Azure?

PHP is frequently used on Azure App Services (aka Microsoft Azure, Windows Azure, Azure Web Apps). Azure App Services manages pools of Windows Web Servers to host your web application, as an alternative to managing your own web server on your own Azure Compute VMs or other servers.

Can Azure Functions replace Web API?

Conclusion. Migrating from a simple web API that has little commercial pressure to Azure Function can save significant development and operational costs. By using the serverless platform, we can focus on the business logic itself rather than the infrastructure code.

Can you host a website on Azure Functions?

Azure App Service is the fastest and easiest way to host web applications and APIs in Azure. Azure App Service provides a fully managed, platform as a service hosting solution that supports . NET, Java, JavaScript, and Python applications.

Can Azure function used as API?

Azure API Management supports importing Azure Function Apps as new APIs or appending them to existing APIs. The process automatically generates a host key in the Azure Function App, which is then assigned to a named value in Azure API Management.


1 Answers

Ok, unfortunately there's pretty limited documentation out there for php as you have discovered.

At present, looking at the code might be the best doc. Here is the InitializeHttpRequestEnvironmentVariables function that adds request metadata to the environment for the script languages (node, powershell, php, python).

Important environment variables are:

  • REQ_ORIGINAL_URL
  • REQ_METHOD
  • REQ_QUERY
  • REQ_QUERY_<queryname>
  • REQ_HEADERS_<headername>
  • REQ_PARAMS_<paramname>

I'm assuming you've made a GET request, in which case there is no content (req is an empty file), but you will see that these other environment variables contain request data. If you were to make a POST request with a body then req would have data.

like image 125
Matt Mason Avatar answered Sep 28 '22 11:09

Matt Mason