Repository navigation
PHP functions and constants provided by FrankenPHP are not usable in CLI #2301
Copy link
Copy link
Closed
Description
Hello,
First of all, thanks for this great project!
It seems none of the PHP functions and constants defined by FrankenPHP cannot be called when running a CLI script.
I've iterated through all the ones defined in the stub file and cannot use any:
$ curl http://localhost:8080/script.php
==== Constants ====
FRANKENPHP_LOG_LEVEL_DEBUG: 🗸
FRANKENPHP_LOG_LEVEL_INFO: 🗸
FRANKENPHP_LOG_LEVEL_WARN: 🗸
FRANKENPHP_LOG_LEVEL_ERROR: 🗸
==== Functions ====
apache_request_headers: 🗸
apache_response_headers: 🗸
fastcgi_finish_request: 🗸
frankenphp_finish_request: 🗸
frankenphp_finish_request: 🗸
frankenphp_handle_request: 🗸
frankenphp_log: 🗸
frankenphp_request_headers: 🗸
frankenphp_request_headers: 🗸
frankenphp_request_headers: 🗸
frankenphp_response_headers: 🗸
frankenphp_response_headers: 🗸
getallheaders: 🗸
headers_send: 🗸
mercure_publish: 🗸
$ docker compose exec php php /app/public/script.php
==== Constants ====
FRANKENPHP_LOG_LEVEL_DEBUG: 𐄂
FRANKENPHP_LOG_LEVEL_INFO: 𐄂
FRANKENPHP_LOG_LEVEL_WARN: 𐄂
FRANKENPHP_LOG_LEVEL_ERROR: 𐄂
==== Functions ====
apache_request_headers: 𐄂
apache_response_headers: 𐄂
fastcgi_finish_request: 𐄂
frankenphp_finish_request: 𐄂
frankenphp_finish_request: 𐄂
frankenphp_handle_request: 𐄂
frankenphp_log: 𐄂
frankenphp_request_headers: 𐄂
frankenphp_request_headers: 𐄂
frankenphp_request_headers: 𐄂
frankenphp_response_headers: 𐄂
frankenphp_response_headers: 𐄂
getallheaders: 𐄂
headers_send: 𐄂
mercure_publish: 𐄂
$ docker compose exec php frankenphp php-cli /app/public/script.php
==== Constants ====
FRANKENPHP_LOG_LEVEL_DEBUG: 𐄂
FRANKENPHP_LOG_LEVEL_INFO: 𐄂
FRANKENPHP_LOG_LEVEL_WARN: 𐄂
FRANKENPHP_LOG_LEVEL_ERROR: 𐄂
==== Functions ====
apache_request_headers: 𐄂
apache_response_headers: 𐄂
fastcgi_finish_request: 𐄂
frankenphp_finish_request: 𐄂
frankenphp_finish_request: 𐄂
frankenphp_handle_request: 𐄂
frankenphp_log: 𐄂
frankenphp_request_headers: 𐄂
frankenphp_request_headers: 𐄂
frankenphp_request_headers: 𐄂
frankenphp_response_headers: 𐄂
frankenphp_response_headers: 𐄂
getallheaders: 𐄂
headers_send: 𐄂
mercure_publish: 𐄂
Reproduction script
<?php
// script.php
echo '==== Constants ====' . \PHP_EOL;
$constants = [
'FRANKENPHP_LOG_LEVEL_DEBUG',
'FRANKENPHP_LOG_LEVEL_INFO',
'FRANKENPHP_LOG_LEVEL_WARN',
'FRANKENPHP_LOG_LEVEL_ERROR',
];
foreach ($constants as $constant) {
echo $constant . ': ' . (\defined($constant) ? '🗸' : '𐄂') . \PHP_EOL;
}
echo \PHP_EOL . '==== Functions ====' . \PHP_EOL;
$functions = [
'apache_request_headers',
'apache_response_headers',
'fastcgi_finish_request',
'frankenphp_finish_request',
'frankenphp_finish_request',
'frankenphp_handle_request',
'frankenphp_log',
'frankenphp_request_headers',
'frankenphp_request_headers',
'frankenphp_request_headers',
'frankenphp_response_headers',
'frankenphp_response_headers',
'getallheaders',
'headers_send',
'mercure_publish',
];
foreach ($functions as $function) {
echo $function . ': ' . (\function_exists($function) ? '🗸' : '𐄂') . \PHP_EOL;
}# compose.yaml
services:
php:
image: dunglas/frankenphp:1.12.1
environment:
SERVER_NAME: :80
volumes:
- ./script.php:/app/public/script.php
ports:
- 8080:80Is this expected?
My intended use case was running a (Symfony) console command directly in the container and pushing its results to clients with mercure_publish().
I opened an issue cause I feel like it's a bug but feel free to make it a discussion if it's more appropriate.
I'm available if you have any question.
Thanks!
Metadata
Metadata
Assignees
Labels
No labels
Activity
henderkes commentedon Mar 24, 2026
The only one that makes some kind of sense to be available in CLI context is
mercure_publish, but since the frankenphp php-cli call isn't the one that has the mercure server running, that wouldn't work either, it would have to take the trip to the http api.So no, it makes sense that these are not available in cli context.
bcourtel commentedon Mar 24, 2026
OK, thank you! I'll change my code to push the update to the embedded Mercure Hub.
Out of curiosity (haven't tried it), does that mean that a PHP function exposed by a FrankenPHP Go extension would not be usable from the CLI context?
henderkes commentedon Mar 24, 2026
Regular php extensions written in Go are available in CLI context.
bcourtel commentedon Mar 24, 2026
Nice, I'll close the issue now.
Thanks again, have a great day
dunglas commentedon Mar 24, 2026
frankenphp_log() could be interesting too
henderkes commentedon Mar 24, 2026
How? We couldn't redirect it to the log stream of a running service, so it would just end up being spat out in the console like
echo.dunglas commentedon Mar 24, 2026
Yes but it could be nice to emit structured logs from the CLI. Not sure if it is easy to implement though
henderkes commentedon Mar 24, 2026
Eh, I think that's better left to libraries, rather than an extension that would only work with the (current incomplete) frankenphp fake php-cli.
Unfortunately my PR at php/php-src#21354 isn't getting much traction yet.