Skip to content

PHP functions and constants provided by FrankenPHP are not usable in CLI #2301

Closed

Description

@bcourtel

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:80

Is 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!

Activity

  1. henderkes commented on Mar 24, 2026

    @henderkes
    Contributor

    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.

  2. bcourtel commented on Mar 24, 2026

    @bcourtel
    Author

    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?

  3. henderkes commented on Mar 24, 2026

    @henderkes
    Contributor

    Regular php extensions written in Go are available in CLI context.

  4. bcourtel commented on Mar 24, 2026

    @bcourtel
    Author

    Nice, I'll close the issue now.

    Thanks again, have a great day

  5. dunglas commented on Mar 24, 2026

    @dunglas
    Member

    frankenphp_log() could be interesting too

  6. henderkes commented on Mar 24, 2026

    @henderkes
    Contributor

    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.

  7. dunglas commented on Mar 24, 2026

    @dunglas
    Member

    Yes but it could be nice to emit structured logs from the CLI. Not sure if it is easy to implement though

  8. henderkes commented on Mar 24, 2026

    @henderkes
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions