frankenphp icon indicating copy to clipboard operation
frankenphp copied to clipboard

Unexpected termination, restarting

Open RikudouSage opened this issue 2 years ago • 13 comments

I get this error after just trying to run an app in worker mode.

It prints this error all over in the log:

{"level":"error","ts":1700923502.7101762,"msg":"unexpected termination, restarting","worker":"/app/public/index.php","exit_status":255}

It's running in docker (using docker compose):

  webserver:
    image: dunglas/frankenphp
    environment:
      FRANKENPHP_CONFIG: worker ./public/index.php
      APP_RUNTIME: Runtime\\FrankenPhpSymfony\\Runtime
    volumes:
      - $PWD:/app
    ports:
      - "8001:443"

RikudouSage avatar Nov 25 '23 14:11 RikudouSage

Could you show your composer.json file? It looks like your worker isn't working properly.

dunglas avatar Nov 25 '23 18:11 dunglas

I've reset the changes, so the runtime is not there now, but when I tested it, it was installed there.

composer.json

RikudouSage avatar Nov 25 '23 20:11 RikudouSage

The runtime/frankenphp-symfony package looks missing.

Can you install it and be sure to follow this documentation to see if the problem persists? https://github.com/dunglas/frankenphp/blob/main/docs/worker.md#symfony-runtime

dunglas avatar Nov 28 '23 21:11 dunglas

As I said, this is reverted to the original version before trying FrankenPHP and the runtime was there when I tried it.

RikudouSage avatar Nov 29 '23 08:11 RikudouSage

If possible could you provide a reproducer? It's hard to tell without seeing/trying the code.

dunglas avatar Dec 14 '23 00:12 dunglas

I'll try.

RikudouSage avatar Dec 14 '23 10:12 RikudouSage

I had the same. The docs is saying:

docker run \
    -e FRANKENPHP_CONFIG="worker ./public/index.php" \
    -e APP_RUNTIME=Runtime\\FrankenPhpSymfony\\Runtime \
    -v $PWD:/app \
    -p 80:80 -p 443:443 \
    dunglas/frankenphp

When I've changed double slash to single one in APP_RUNTIME it worked:

    -e APP_RUNTIME='Runtime\FrankenPhpSymfony\Runtime' \

aglowienka avatar Dec 26 '23 12:12 aglowienka

Hello,

I also meet this problem when using the worker mode on a new tiny vanilla PHP project (for testing purposes), although the index.php works well in standard mode.

{"level":"error","ts":1705486764.5677447,"msg":"unexpected termination, restarting","worker":"/app/public/index.php","exit_status":255}

After a few seconds, it eventually terminates with the following error

<br />
<b>Fatal error</b>:  Could not create timer: Resource temporarily unavailable (11) in <b>Unknown</b> on line <b>0</b><br />

My composer.json is empty (no dependency installed):

{
    "config": {
    }
}

My index.php, inspired by the template for custom apps:

<?php

class Kernel
{
    public function boot()
    {
        echo 'Boot';
    }

    public function handle($get, $post, $cookie, $files, $server)
    {
        echo '<br>Handle: ' . Date('Y-m-d H:i:s');
    }

    public function terminate()
    {
        echo '<br>Terminate';
    }

    public function shutdown()
    {
        echo '<br>Shutdown';
    }
}

$myApp = new \Kernel();
$myApp->boot();

$handler = static function () use ($myApp) {
    echo $myApp->handle($_GET, $_POST, $_COOKIE, $_FILES, $_SERVER);
};

for (
    $nbRequests = 0, $running = true;
    isset($_SERVER['MAX_REQUESTS']) &&
    $nbRequests < ((int) $_SERVER['MAX_REQUESTS']) &&
    $running;
    ++$nbRequests
) {
    $running = \frankenphp_handle_request($handler);

    $myApp->terminate();

    gc_collect_cycles();
}

// Cleanup
$myApp->shutdown();

pierresh avatar Jan 17 '24 10:01 pierresh

Hello,

I also meet this problem when using the worker mode on a new tiny vanilla PHP project (for testing purposes), although the index.php works well in standard mode.

{"level":"error","ts":1705486764.5677447,"msg":"unexpected termination, restarting","worker":"/app/public/index.php","exit_status":255}

After a few seconds, it eventually terminates with the following error

<br />
<b>Fatal error</b>:  Could not create timer: Resource temporarily unavailable (11) in <b>Unknown</b> on line <b>0</b><br />

My composer.json is empty (no dependency installed):

{
    "config": {
    }
}

My index.php, inspired by the template for custom apps:

<?php

class Kernel
{
    public function boot()
    {
        echo 'Boot';
    }

    public function handle($get, $post, $cookie, $files, $server)
    {
        echo '<br>Handle: ' . Date('Y-m-d H:i:s');
    }

    public function terminate()
    {
        echo '<br>Terminate';
    }

    public function shutdown()
    {
        echo '<br>Shutdown';
    }
}

$myApp = new \Kernel();
$myApp->boot();

$handler = static function () use ($myApp) {
    echo $myApp->handle($_GET, $_POST, $_COOKIE, $_FILES, $_SERVER);
};

for (
    $nbRequests = 0, $running = true;
    isset($_SERVER['MAX_REQUESTS']) &&
    $nbRequests < ((int) $_SERVER['MAX_REQUESTS']) &&
    $running;
    ++$nbRequests
) {
    $running = \frankenphp_handle_request($handler);

    $myApp->terminate();

    gc_collect_cycles();
}

// Cleanup
$myApp->shutdown();

I can make my script work if I change the lines

for (
    $nbRequests = 0, $running = true;
    isset($_SERVER['MAX_REQUESTS']) &&
    $nbRequests < ((int) $_SERVER['MAX_REQUESTS']) &&
    $running;
    ++$nbRequests
) {

to

for (
    $nbRequests = 0, $running = true;
    $nbRequests < 5 && $running;
    ++$nbRequests
) {

The problem is related to _$SERVER['MAX_REQUESTS']; which is undefined.

pierresh avatar Jan 19 '24 10:01 pierresh

I'm having this on macOS with Laravel & Octane.

nikspyratos avatar Jan 20 '24 18:01 nikspyratos

Could not create timer: Resource temporarily unavailable

This is due to #440 and is fixed upstream in PHP, but not released yet.

The problem is related to _$SERVER['MAX_REQUESTS']; which is undefined.

Digging around a bit, I think you need to set the env in the caddyfile to get this to work.

Try setting your FRANKENPHP_CONFIG to something like:

FRANKENPHP_CONFIG="worker /path/to/script.php \
env MAX_REQUESTS 25"

withinboredom avatar Jan 21 '24 09:01 withinboredom

I had a similar situation. Depending on how you run your app you need to define the environment variable MAX_REQUESTS somewhere. Also you can add $_SERVER['MAX_REQUESTS'] ??= 500; before your for loop as a fallback.

rikwillems avatar Apr 16 '24 08:04 rikwillems