PHP code example of alencarfreire / stem

1. Go to this page and download the library: Download alencarfreire/stem library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

alencarfreire / stem example snippets




declare(strict_types=1);



$app = new App();
$app->notFound(fn (Request $r) => $r->json(['error' => 'not_found'], 404));

$app->route(function (Request $r): void {
    $r->root(fn () => $r->json(['ok' => true]));

    $r->on('users', function () use ($r): void {
        $r->get(fn () => $r->json([['id' => 1, 'name' => 'Ada']]));

        $r->post(function () use ($r): void {
            $name = ($r->jsonBody() ?? [])['name'] ?? '';
            if ($name === '') {
                $r->json(['error' => 'name 

$response = $app->handle(Request::create('GET', '/users/1'));

use Stem\Integrations\FrankenPhpWorker;

FrankenPhpWorker::run($app, maxRequests: (int) ($_SERVER['MAX_REQUESTS'] ?? 0));
// collectEvery: 0 (default) skips gc_collect_cycles(); set e.g. 128 if a leaky extension forces it.
bash
php -S 127.0.0.1:8080 index.php
wrk -t4 -c20 -d10s --latency http://127.0.0.1:8080/customers