php / php/frankenphp

Unexpected Termination (255)

Open
#774 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Go
Stars
11.3k
Forks
488
Avg merge
4d 10h
Merged PRs (30d)
11

Description

What happened?

Hey All!

Im trying to see if its possible to get Xenforo working with FrankenPHP.

This is my Caddyfile

{
    {$CADDY_GLOBAL_OPTIONS}

    frankenphp {
        worker ./worker.php
    }

    order mercure after encode
    order vulcain after reverse_proxy
    order php_server before file_server
    order php before file_server
}

forum.mydomain.net {
    # Set the root to the /xenforo directory
    root * /app

    # Enable compression encoders
    encode zstd br gzip

    # Include additional server directives (if any)
    {$CADDY_SERVER_EXTRA_DIRECTIVES}

    php_server {
        index index.php
    }

    # Additional configurations for Xenforo can be placed here
    tls {
        dns cloudflare {env.CF_API_TOKEN}
    }
}

This is my worker.php that I have tried to make to work well with Xenforo

<?php
// /app/worker.php

// Prevent worker script termination when a client connection is interrupted
ignore_user_abort(true);

// Boot Xenforo
// Adjust the path to reflect the location of Xenforo's initialization file
require __DIR__ . '/src/XF.php';

// Start the application
\XF::start();

// Handler outside the loop for better performance (doing less work)
$handler = static function () {
    // Called when a request is received
    $app = \XF::setupApp('XF\Pub\App');

    // Process the request and return the response
    $response = $app->run();
    $response->send();
};

// Handle requests with a limit on the number of requests or other termination conditions
for ($nbRequests = 0, $running = true; isset($_SERVER['MAX_REQUESTS']) && ($nbRequests < (int)$_SERVER['MAX_REQUESTS']) && $running; ++$nbRequests) {
    $running = \frankenphp_handle_request($handler);

    // Do something after sending the HTTP response
    $app->terminate();

    // Call the garbage collector
    gc_collect_cycles();
}

// Cleanup (if applicable)
\XF::shutdown();

However when I do docker compose up you can see from the logs what it spams in my console.
I gather its an issue to do with the worker.php but I have no clue where to start to figure out what the issue may be?

Any guidance would be greatly appreciated! :)

docker-composer.yml if its of any use

services:
  frankenphp:
    image: xenforo-forum
    restart: always
    ports:
      - "8080:80"        # HTTP
      - "9445:443"      # HTTPS
      - "9445:443/udp"  # HTTP/3
    volumes:
      - /home/josh/xenforo:/app
      - /home/josh/xenforo-environment/Caddyfile:/caddy-config/Caddyfile
      - caddy_data:/data
      - caddy_config:/config
    environment:
      - MAX_REQUESTS=1000
    command: ["--config", "/caddy-config/Caddyfile"]

volumes:
  caddy_data:
  caddy_config:
Build Type

Docker (Debian Bookworm)

Worker Mode

Yes

Operating System

GNU/Linux

CPU Architecture

x86_64

PHP configuration
N/A
Relevant log output
frankenphp-1  | {"level":"error","ts":1715298046.7656398,"msg":"unexpected termination, restarting","worker":"/app/worker.php","exit_status":255}
frankenphp-1  | {"level":"error","ts":1715298046.7660913,"msg":"unexpected termination, restarting","worker":"/app/worker.php","exit_status":255}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing worker.php alongside the provided Caddyfile and docker-compose.yml, then run docker compose up while capturing the PHP error output associated with exit status 255. Determine why the worker terminates and document a reproducible configuration that starts without repeated unexpected-termination messages.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, docker-compose, php
Domain
backend, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.