veasin/nx-tiny-franken

FrankenPHP worker integration for nx-tiny micro-framework.

Maintainers

Package info

github.com/veasin/nx-tiny-franken

pkg:composer/veasin/nx-tiny-franken

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.0.2 2026-05-10 08:39 UTC

This package is auto-updated.

Last update: 2026-05-10 08:42:06 UTC


README

FrankenPHP worker mode adapter for nx-tiny micro-framework.

Install

composer require veasin/nx-tiny-franken

Usage

<?php
// franken.php - FrankenPHP worker entry point
include __DIR__ . '/vendor/autoload.php';

use function nx\{container, franken, from, log, output, route};

container('count', 0);

franken(function () {
    log(from('uri', 'input'));

    route([
        'get:/'         => fn() => output('hello world!', 'http'),
        'get:/hi'       => fn() => output('hi~', 'http'),
        'get:/count'    => function () {
            $count = container('count') + 1;
            output("count: $count", 'http');
            container('count', $count);
        },
    ]);
}, function () {
    // cleanup on each request cycle end
});

Caddyfile

localhost {
    log
    root demo/
    php_server {
        try_files {path} franken.php
        worker {
            file ./demo/franken.php
            watch ./src/**/*.php
            watch ./demo/**/*.php
            num 4
        }
    }
}

Run with:

frankenphp run --config demo/Caddyfile

API

franken(callable $worker, ?callable $clear): void

Wraps the FrankenPHP worker loop:

  • Sets up a PSR-3 compatible logger via frankenphp_log() on first call.
  • Calls $worker() on each request. If $worker() returns a truthy value, subsequent output/cleanup is skipped.
  • Calls $clear() after each request cycle ends (if callable).

License

LGPL-3.0-or-later