You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a way to determine if code is running in worker mode or not? It would be nice to have something like \frankenphp_handler that would return: worker, standard or maybe \frankenphp_is_worker(_mode) ? Or maybe a constant?
Can we get worker name in the code somehow? So we can also use it in logs for example?
I wonder if there should be a internal variable in Caddyfile worker config for max number of handled requests. When that number is reached then \frankenphp_handle_request would return false?. That would simplified code. I think now is the last moment to do change like that so new code does not have to include a that loop with a counter. This setting could accept -1 to state that user wants to control that with a loop in the application...
So from this:
$maxRequests = (int)($_SERVER['MAX_REQUESTS'] ?? 0);
for ($nbRequests = 0; !$maxRequests || $nbRequests < $maxRequests; ++$nbRequests) {
$keepRunning = \frankenphp_handle_request($handler);
// Do something after sending the HTTP response$myApp->terminate();
// Call the garbage collector to reduce the chances of it being triggered in the middle of a page generationgc_collect_cycles();
if (!$keepRunning) break;
}
do {
$shouldContinue = \frankenphp_handle_request($handler);
} while ($shouldContinue);
or this:
do {
$shouldContinue = \frankenphp_handle_request($handler);
$myApp->terminate();
gc_collect_cycles();
} while ($shouldContinue);
Can we get something in the docs about PDO and connection management? Let's imagine we have a slower day (for example a Sunday afternoon for a SaaS). There is a chance that there will be no requests for a moment. I am pretty sure that PDO will reconnect BUT I am not 100% sure. I am also not sure about other persistent connections like Redis?
I could not find anything about session management in the documentation. I assume I need to call session_start() and session_write_close() inside of my handler, correct?
FrankenPHP is a great piece of software :) Keep up the great work!! :)
I think currently there is no direct way to determine if code is running in worker mode unless you are booting the worker script. When booting, $_SERVER['FRANKENPHP_WORKER'] should be '1'. You could then theoretically set your own global variable during setup. But I'm generally not opposed to providing some option like this.
Currently there's also no way to determine the name of the current worker script. Feel free to open a feature request!
A max number of requests via Caddyfile would definitely be possible, I remember @dunglas being against doing this though at some point, unless he's changed his mind.
I've never had problems with PDO or Redis connections timing out and breaking, even on non-busy applications. If you have a long-running request or persistent connections with regular PHP, they can also potentially break during that request, so drivers probably automatically reconnect also in those cases (just my guess though).
That being said, I'm not sure if this could potentially be a problem in some cases even if no issues like that have been raised yet.
To mitigate against this, you could also set worker threads to 1 and a high number of max_threads. So all non-busy threads will automatically stop and close all connections.
If this really turns out to be an issue for some people with some drivers, a feature to limit the amount of time worker can run before restarting would also be a possibility.
Not sure about native sessions since I haven't been using them myself, but I assume they work as with regular PHP (I at least know that the session module gets reloaded in worker mode between requests)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
Is there a way to determine if code is running in worker mode or not? It would be nice to have something like
\frankenphp_handlerthat would return: worker, standard or maybe\frankenphp_is_worker(_mode)? Or maybe a constant?Can we get worker name in the code somehow? So we can also use it in logs for example?
I wonder if there should be a internal variable in Caddyfile worker config for max number of handled requests. When that number is reached then
\frankenphp_handle_requestwould return false?. That would simplified code. I think now is the last moment to do change like that so new code does not have to include a that loop with a counter. This setting could accept -1 to state that user wants to control that with a loop in the application...So from this:
to this:
{ frankenphp { worker { file /app/public/worker.php max_requests 5000 } } }or this:
Can we get something in the docs about PDO and connection management? Let's imagine we have a slower day (for example a Sunday afternoon for a SaaS). There is a chance that there will be no requests for a moment. I am pretty sure that PDO will reconnect BUT I am not 100% sure. I am also not sure about other persistent connections like Redis?
I could not find anything about session management in the documentation. I assume I need to call
session_start()andsession_write_close()inside of my handler, correct?FrankenPHP is a great piece of software :) Keep up the great work!! :)
Beta Was this translation helpful? Give feedback.
All reactions