Content · Programming · PHP

PHP apcu_enabled() Function: Usage and Examples

Learn how PHP apcu_enabled works with practical examples, important behavior, relevant alternatives and common mistakes.

1 views Published Oct 16, 2026 Updated Oct 16, 2026

Reports whether APCu is available for the current PHP process.

What Is apcu_enabled() in PHP?

Reports whether APCu is available for the current PHP process.

Its syntax is:

apcu_enabled(): bool

Parameters:

    Return type: bool. A CLI process may have APCu disabled even when the web server uses it. First test function_exists() when APCu might be absent.

    Availability: Requires APCu enabled for the current PHP SAPI.

    Example 1: Basic Usage

    <?php
    
    var_dump(apcu_enabled());
    

    Result: Results and availability depend on the current PHP process, system permissions, cache, filesystem or installed locale. A CLI process may have APCu disabled even when the web server uses it. First test function_exists() when APCu might be absent.

    Example 2: A Different Input

    <?php
    
    echo apcu_enabled() ? "Cache available" : "Cache unavailable";
    

    Result: Results and availability depend on the current PHP process, system permissions, cache, filesystem or installed locale. A CLI process may have APCu disabled even when the web server uses it. First test function_exists() when APCu might be absent.

    Practical Example: Applying It in a Program

    <?php
    
    if (function_exists("apcu_enabled") && apcu_enabled()) {
        apcu_store("health", "ok", 30);
    } else { echo "Using uncached fallback"; }
    

    Result: Results and availability depend on the current PHP process, system permissions, cache, filesystem or installed locale. A CLI process may have APCu disabled even when the web server uses it. First test function_exists() when APCu might be absent.

    Important Behavior and Edge Cases

    • Key behavior: A CLI process may have APCu disabled even when the web server uses it. First test function_exists() when APCu might be absent.
    • Environment: Requires APCu enabled for the current PHP SAPI.

    Comparison With Related Functions

    FunctionPurpose
    apcu_enabled()reports whether APCu is available for the current PHP process.
    extension_loaded()extension_loaded("apcu") checks installation; apcu_enabled() checks that APCu can be used in the current environment.

    Common Beginner Mistakes

    MistakeCorrect Approach
    Ignoring this behavior: A CLI process may have APCu disabled even when the web server uses itA CLI process may have APCu disabled even when the web server uses it. First test function_exists() when APCu might be absent.

    Key Takeaways

    • reports whether APCu is available for the current PHP process.
    • A CLI process may have APCu disabled even when the web server uses it. First test function_exists() when APCu might be absent.
    • Requires APCu enabled for the current PHP SAPI.

    Summary: A CLI process may have APCu disabled even when the web server uses it. First test function_exists() when APCu might be absent.

    Share this resourceSend this page to someone who may find it useful.