├── .do └── deploy.template.yaml ├── README.md └── packages └── sample └── hello └── index.php /.do/deploy.template.yaml: -------------------------------------------------------------------------------- 1 | alerts: 2 | - rule: DEPLOYMENT_FAILED 3 | - rule: DOMAIN_FAILED 4 | functions: 5 | - github: 6 | branch: main 7 | deploy_on_push: true 8 | repo: digitalocean/sample-functions-php-helloworld 9 | name: php-api 10 | routes: 11 | - path: / 12 | source_dir: / 13 | name: php-helloworld 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sample Function: PHP "Hello World" 2 | 3 | ## Introduction 4 | 5 | This repository contains a sample "Hello World" function written in PHP. You can deploy it on DigitalOcean's App Platform as a Serverless Function component or as a standalone Function. Documentation is available at https://docs.digitalocean.com/products/functions. 6 | 7 | ### Requirements 8 | 9 | * You need a DigitalOcean account. If you don't already have one, you can sign up at [https://cloud.digitalocean.com/registrations/new](https://cloud.digitalocean.com/registrations/new). 10 | * To deploy from the command line, you will need the [DigitalOcean `doctl` CLI](https://github.com/digitalocean/doctl/releases). 11 | 12 | ## Deploying the Function 13 | 14 | ``` 15 | # clone this repo 16 | git clone git@github.com:digitalocean/sample-functions-php-helloworld.git 17 | ``` 18 | 19 | ``` 20 | # deploy the project, using a remote build so that compiled executable matched runtime environment 21 | doctl serverless deploy sample-functions-php-helloworld --remote-build 22 | ``` 23 | 24 | The output from the deploy command will resemble the following. 25 | ``` 26 | Deploying 'sample-functions-php-helloworld' 27 | to namespace 'fn-...' 28 | on host '...' 29 | Deployment status recorded in 'sample-functions-php-helloworld/.deployed' 30 | 31 | Deployed functions ('doctl sls fn get --url' for URL): 32 | - sample/hello 33 | ``` 34 | 35 | ## Using the Function 36 | ``` 37 | doctl serverless functions invoke sample/hello 38 | ``` 39 | 40 | This will return the default response from the function. 41 | ``` 42 | { 43 | "body": "Hello stranger!" 44 | } 45 | ``` 46 | 47 | You can pass a parameter to your function using the `-p` command line argument. 48 | ``` 49 | doctl serverless functions invoke sample/hello -p name:functions 50 | { 51 | "body": "Hello functions!" 52 | } 53 | ``` 54 | 55 | Use this command to retrieve the URL for your function and use it as an API. 56 | ``` 57 | doctl sls fn get sample/hello --url 58 | ``` 59 | 60 | You can use that API directly in your browser, with `curl` or with an API platform such as Postman. 61 | Parameters may be passed as query parameters, or as JSON body. Here are some examples using `curl`. 62 | 63 | ``` 64 | curl `doctl sls fn get sample/hello --url`?name=query 65 | ``` 66 | 67 | ``` 68 | curl -H 'Content-Type: application/json' -d '{"name":"body"}' `doctl sls fn get sample/hello --url` 69 | ``` 70 | 71 | ### Learn More 72 | 73 | You can learn more about Functions by reading the [Functions Documentation](https://docs.digitalocean.com/products/functions). 74 | -------------------------------------------------------------------------------- /packages/sample/hello/index.php: -------------------------------------------------------------------------------- 1 | $greeting, 12 | ]; 13 | } 14 | --------------------------------------------------------------------------------