Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Lozza's avatar
Level 4

Call to undefined function Illuminate\Cache\apc_fetch()

I have just installed stripe and since composer has performed it's updates, I now get the above error when trying to use the cache facade:

$array = Cache::rememberForever("SumBySlot:{$slot_id}", function() use($slot_id)

I have tried reverting and rebuilding but I guess an update was pending, so it still fails. :-(

Any help gratefully receives as usual :-)

Here is my composer.json:

{

    "name": "laravel/laravel",
    "type": "project",
    "description": "The skeleton application for the Laravel framework.",
    "keywords": [
        "laravel",
        "framework"
    ],
    "license": "MIT",
    "require": {
        "php": "^8.1",
        "filament/filament": ">3.0",
        "guzzlehttp/guzzle": "^7.2",
        "laravel/framework": "^10.10",
        "laravel/jetstream": "^4.0",
        "laravel/sanctum": "^3.3",
        "laravel/tinker": "^2.8",
        "livewire/livewire": "^3.0",
        "stripe/stripe-php": "^13.9"
    },
    "require-dev": {
        "fakerphp/faker": "^1.9.1",
        "laravel/pint": "^1.0",
        "laravel/sail": "^1.18",
        "mockery/mockery": "^1.4.4",
        "nunomaduro/collision": "^7.0",
        "phpunit/phpunit": "^10.1",
        "spatie/laravel-ignition": "^2.0"
    },
    "autoload": {
        "psr-4": {
            "App\": "app/",
            "Database\Factories\": "database/factories/",
            "Database\Seeders\": "database/seeders/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\": "tests/"
        }
    },
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\Foundation\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi",
            "@php artisan filament:upgrade"
        ],
        "post-update-cmd": [
            "@php artisan vendor:publish --tag=laravel-assets --ansi --force"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true,
        "allow-plugins": {
            "pestphp/pest-plugin": true,
            "php-http/discovery": true
        }
    },
    "minimum-stability": "stable",
    "prefer-stable": true
}
0 likes
4 replies
LaryAI's avatar
Level 58

It seems like you're encountering an issue with the APC cache driver in Laravel. The error "Call to undefined function Illuminate\Cache\apc_fetch()" indicates that the APC extension is not installed or enabled in your PHP configuration.

Here's how you can resolve this issue:

  1. Check if APC is installed: Run php -m in your terminal to see if APC is listed as one of the PHP modules. If it's not listed, you need to install it.

  2. Install APCu for PHP 8.x: Since APC is not officially supported in PHP 7 and above, you should use APCu, which is a userland caching APC replacement. You can install it using pecl:

    pecl install apcu
    
  3. Enable APCu in your PHP configuration: After installing APCu, you need to enable it in your php.ini file. Add the following lines:

    extension=apcu.so
    apc.enabled=1
    apc.enable_cli=1
    

    The apc.enable_cli=1 setting is particularly important for CLI operations, such as those performed by Composer.

  4. Configure Laravel to use APCu: In your .env file, make sure you have the cache driver set to use APC:

    CACHE_DRIVER=apc
    
  5. Clear config cache: After making changes to your .env file or php.ini, you should clear the Laravel config cache:

    php artisan config:clear
    
  6. Restart your web server: To ensure that all changes take effect, restart your web server and PHP-FPM (if you're using it).

  7. Verify APCu is working: You can verify that APCu is enabled and working by creating a simple PHP script that calls phpinfo() and checking for the APCu section in the output.

If you've followed these steps and are still encountering issues, it might be worth checking if any other cache configuration in your config/cache.php file is referencing APC functions or if there are any other parts of your application that might be doing so.

Here's a simple example of how you might use APCu for caching in Laravel:

$array = Cache::rememberForever("SumBySlot:{$slot_id}", function () use ($slot_id) {
    // Your logic to generate the data to be cached
    return $calculatedData;
});

Make sure that your server environment matches the requirements of your Laravel application and that all necessary PHP extensions are installed and enabled. If you're still having trouble, consider reaching out to your hosting provider or checking your server's error logs for more detailed information about the issue.

Lozza's avatar
Level 4

I have changed the CACHE_DRIVER from

CACHE_DRIVER=apc

to

CACHE_DRIVER=array

which is now working ok.

I am confused how apc worked before the stripe update.. but I guess I shouldn't waste my time on that!!

Is array the most efficient cache driver for me to use?

JussiMannisto's avatar

@Lozza No, that won't work. Array cache is kept in memory and is not persisted between requests. It's only meant for automated testing.

You can start with the file cache. If you ever need more performance, you may want look at something like Redis. But the file cache goes a long way.

Please or to participate in this conversation.