Skip to content

Error in CLI "APCu is not enabled" #189

@motoronik

Description

@motoronik

Hello.

I use

  • Symfony (7.1.9)
  • artprima/prometheus-metrics-bundle (1.19.0)
  • promphp/prometheus_client_php (2.13.1)

After implementing a custom MetricsCollector (to collect metrics in my services), my CLI commands console commands stopped starting with error: "APCu is not enabled".

class MetricsCollectorService implements MetricsCollectorInterface
{
    use MetricsCollectorInitTrait;
    
    public function someFoo(...): void 
    {
        // some implementation
    }

When the command is run while symfony dependency container initialization, it is checked whether apc is activated and if not, an exception falls on this line. https://github.com/PromPHP/prometheus_client_php/blob/main/src/Prometheus/Storage/APCng.php#L56

Prometheus\Exception\StorageException
APCu is not enabled

I understand that apc makes no sense in a cli environment, but in this case, console commands will crash.

I see several ways to solve the problem:

  1. `apc.enable_cli=1' - it will be pointless to collect metrics, but the console commands will work and it will fix my problem;
  2. Implement method init in my collector and check in it whether the module (apc) is loaded, if it is not loaded, it quietly exits the method without throwing an exception.

The first option looks like it is more convenient and also consistent from the point of view of the code. I won't have to implement workarounds to check if the module is loaded.

Do you have a recommendation on which way would be preferable?

I think it makes sense to write about this situation in this place so that people don't forget about this problem. https://github.com/PromPHP/prometheus_client_php/blob/main/README.md?plain=1#L49

Thanks!

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