Interactive Serverless Playground

ย 

30.05.2020

@xf3l1x
f3l1x.io

Why

Why?

  1. Idea
  2. Challenge
  3. Experience
  4. Utils & tools
  5. Fun

accepted!

(latte examples)

Research

jsfiddle.net

codesandbox.io

Github Codespaces

regex101.com

3v4l.org

php.wtf

phpstan.org

getrector.org

tinkerwell.app

PHP sandboxes

  1. 3v4l.org (php.wtf)

  2. phpstan.org

  3. getrector.org

  4. tinkerwell.app

  5. w3schools.com

  6. phpfiddle.org

  7. onlinephpfunctions.com

  8. writephponline.com

  9. phptester.net

  10. paiza.io

ARE YOU F*'N KIDDING ME?

Features

Features

  • HTTP-based
  • microservices
  • first-class-nette
  • user-friendly
  • easy-to-maintain
  • persistent
  • zero-costs

How

VPS

  1. Charged 24/7ย 

  2. Maintenance

  3. Security updates

  4. Scaling up/down

WebAssembly

emconfigure ./configure \
  --disable-all \
  --disable-cgi \
  --disable-cli \
  --disable-rpath \
  --disable-phpdbg \
  --with-valgrind=no \
  --without-pear \
  --without-pcre-jit \
  --with-layout=GNU \
  --enable-embed=static \
  --enable-bcmath \
  --enable-json \
  --enable-ctype \
  --enable-mbstring \
  --disable-mbregex \
  --enable-tokenizer
emcc -O3 \
  --llvm-lto 2 \
  -s ENVIRONMENT=web \
  -s EXPORTED_FUNCTIONS='["_pib_eval", "_php_embed_init", "_zend_eval_string", "_php_embed_shutdown"]' \
  -s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall"]' \
  -s MODULARIZE=1 \
  -s EXPORT_NAME="'PHP'" \
  -s TOTAL_MEMORY=134217728 \
  -s ASSERTIONS=0 \
  -s INVOKE_RUN=0 \
  -s ERROR_ON_UNDEFINED_SYMBOLS=0 \
  --preload-file Zend/bench.php \
  libs/libphp7.a pib_eval.o -o out/php.js

Serverless

{
  "functions": {
  }
}

Vercel + PHP

now.json

{
  "functions": {
    "api/index.php": {
      "runtime": "now-php@0.0.9"
    }
  }
}

Vercel + PHP

now.json

๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป

Dreamed Architecture

WEB

Text

STORAGE

NETTE

STRINGS

a

TIME

XYZ

ANALYTICS

SERVICES

Textarea Architecture

UI

DB
(mysql)

save

UI

load

<TEXTAREA>

<CODE>

Name!

lessik

serverless

lesรญk

lessik
โ”œโ”€โ”€ services
โ”‚   โ”œโ”€โ”€ nette (PHP)
โ”‚   โ”‚   โ”œโ”€โ”€ api/*.php
โ”‚   โ”‚   โ”œโ”€โ”€ src
โ”‚   โ”‚   โ”œโ”€โ”€ now.json
โ”‚   โ”‚   โ””โ”€โ”€ composer.json
โ”‚   โ”œโ”€โ”€ strings (PHP)
โ”‚   โ”‚   โ”œโ”€โ”€ api/*.php
โ”‚   โ”‚   โ”œโ”€โ”€ src
โ”‚   โ”‚   โ”œโ”€โ”€ now.json
โ”‚   โ”‚   โ””โ”€โ”€ composer.json
โ”‚   โ”œโ”€โ”€ time (PHP)
โ”‚   โ”‚   โ”œโ”€โ”€ api/*.php
โ”‚   โ”‚   โ”œโ”€โ”€ src
โ”‚   โ”‚   โ”œโ”€โ”€ now.json
โ”‚   โ”‚   โ””โ”€โ”€ composer.json
โ”œโ”€โ”€ sites (JS, TS, Vue)
โ”‚   โ””โ”€โ”€ lessik
โ”‚       โ”œโ”€โ”€ src
โ”‚       โ”œโ”€โ”€ now.json
โ”‚       โ”œโ”€โ”€ tsconfig.json
โ”‚       โ”œโ”€โ”€ tailwind.config.js
โ”‚       โ””โ”€โ”€ package.json
โ””โ”€โ”€ Makefile
make sites-lessik-dev
make services-nette-dev
make services-strings-dev

0.0.0.0:1234

Parcel JS

PHP built-in server

0.0.0.0:8000

PHP built-in server

0.0.0.0:8001

Development

terminals

Development

app.ts

export const NAME = "LESSIK";
export const VERSION = "v0.1";

// Services

export const SERVICE_NETTE = 
	process.env.SERVICE_NETTE || 'http://0.0.0.0:8000';

export const SERVICE_STRINGS = 
	process.env.SERVICE_STRINGS || 'http://0.0.0.0:8001';

Development

request & response

const output = await fetch(SERVICE_NETTE, {body});
<?php declare(strict_types = 1);

$latte = Request::param('code');
$output = ['result' => Runner::doLatte($latte)];

Response::header('content-type', 'application/json');
Response::code(200);
echo Json::encode($output);
exit();

Web UI (0.0.0.0:1234)

Nette Service (0.0.0.0:8000)

DEPLOYMENT

VERCEL

strings-v1.felix.tld

nette-v1.felix.tld

3rd party

  • monitoring

  • telemetry logs

  • error handling

  • analytics

  • custom

Dark Lang

web

Hold Your ๐Ÿ‡๐Ÿ‡๐Ÿ‡

Hold Your ๐Ÿ‡๐Ÿ‡๐Ÿ‡

Subscribe For Invitation

Conclusion

  • think big

  • take challenges

  • explore & conquer

  • share experience

  • have fun

๐Ÿคฉ ๐Ÿ˜ข

Time to selfie ๐Ÿ“ท

Github Sponsors

Thank you

Support My OSS

@xf3l1x
f3l1x.io

?

What? Why? How? No? Oh.

Thank you!

Go LESSIK!

@xf3l1x
f3l1x.io

2020-05-30 - Interactive Serverless Playground

By Milan Felix ล ulc

2020-05-30 - Interactive Serverless Playground

  • 1,022