dunglas / frankenphp

🧟 The modern PHP app server
https://frankenphp.dev
MIT License
6.68k stars 220 forks source link

Panic on PHP request startup #249

Closed Javdu10 closed 10 months ago

Javdu10 commented 11 months ago

Hello!

I was happily testing frankenphp, but I figured that sometimes if I run a K6 load test, the docker container crashes and the last message in the console I have is :

panic: error during PHP request startup

goroutine 183 [running, locked to thread]:
github.com/dunglas/frankenphp.go_execute_script(0xc0006e5801?)
        /go/src/app/frankenphp.go:470 +0x2a5

and sometimes :

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

K6 script ran with k6 run --vus 10000 --duration 30s script.js

import http from 'k6/http';
import { check } from 'k6';

export default function () {
  let res = http.get('https://xxxxxxx');
  check(res, {
    "is status 200": (r) => r.status === 200
  });
}

I am running the docker container from dunglas/frankenphp:sha-b04326e-php8.2-alpine behind cloudflare tunnels, my /app/public/index.php is :

<?php

use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;

define('LARAVEL_START', microtime(true));
echo 'hello world';
exit;

During load test the machine seems to be stable in resource usage, then boom

Please let me know if any other information is needed

dunglas commented 11 months ago

System timers used by PHP to handle max_execution_time etc are a limited resource, and it looks like the stress test reached the limit.

Can you try to increase the limit using ulimit -i?

It should also be possible to improve timer management directly in PHP. It's on my todo list!

Javdu10 commented 11 months ago

Thank you for your reply, indeed changing to unlimited prevents the container from crashing and sends the container to 100% CPU, requests correcly timeout on the stress test