php langhelper (needs funcy/php), tutorial

This commit is contained in:
Chad Arimura
2017-05-26 12:36:38 -07:00
parent 98e05eec63
commit b49337d4e0
10 changed files with 188 additions and 57 deletions

View File

@@ -1,10 +1,41 @@
## Quick Example for a PHP Function (4 minutes)
# Tutorial 1: PHP Function w/ Input (3 minutes)
This example will show you how to test and deploy Go (Golang) code to Oracle Functions.
This example will show you how to test and deploy PHP code to Oracle Functions. It will also demonstrate passing data in through stdin.
### 1. Prepare the `func.yaml` file:
### First, run the following commands:
At func.yaml you will find:
```sh
# Initialize your function creating a func.yaml file
fn init <DOCKERHUB_USERNAME>/hello
# Test your function.
# This will run inside a container exactly how it will on the server. It will also install and vendor dependencies from Gemfile
fn run
# Now try with an input
cat hello.payload.json | fn run
# Deploy your functions to the Oracle Functions server (default localhost:8080)
# This will create a route to your function as well
fn deploy myapp
```
### Now call your function:
```sh
curl http://localhost:8080/r/myapp/hello
```
Or call from a browser: [http://localhost:8080/r/myapp/hello](http://localhost:8080/r/myapp/hello)
And now with the JSON input:
```sh
curl -H "Content-Type: application/json" -X POST -d @hello.payload.json http://localhost:8080/r/myapp/hello
```
That's it!
### Note on Dependencies
```yml
name: USERNAME/hello
@@ -14,25 +45,6 @@ build:
- docker run --rm -v "$PWD":/worker -w /worker funcy/php:dev composer install
```
The important step here is to ensure you replace `USERNAME` with your Docker Hub account name. Some points of note:
the application name is `phpapp` and the route for incoming requests is `/hello`. These informations are relevant for
the moment you try to test this function.
### 2. Build:
```sh
# build the function
fn build
# test it
cat hello.payload.json | fn run
# push it to Docker Hub
fn push
# Create a route to this function on Oracle Functions
fn routes create phpapp /hello
```
`-v` is optional, but it allows you to see how this function is being built.
### 3. Queue jobs for your function
Now you can start jobs on your function. Let's quickly queue up a job to try it out.
@@ -41,8 +53,30 @@ Now you can start jobs on your function. Let's quickly queue up a job to try it
cat hello.payload.json | fn call phpapp /hello
```
Here's a curl example to show how easy it is to do in any language:
```sh
curl -H "Content-Type: application/json" -X POST -d @hello.payload.json http://localhost:8080/r/phpapp/hello
```
# In Review
1. We piped JSON data into the function at the command line
```sh
cat hello.payload.json | fn run
```
2. We received our function input through **stdin**
```node
obj = JSON.parse(fs.readFileSync('/dev/stdin').toString())
```
3. We wrote our output to **stdout**
```node
console.log
```
4. We sent **stderr** to the server logs
```node
console.error
```
# Next Up
## [Tutorial 2: Input Parameters](examples/tutorial/params)