symfony/polyfill-apcu
Symfony Polyfill for APCu: provides apcu_* functions and the APCuIterator class for projects relying on the legacy APC extension, enabling compatible caching APIs when APCu isn’t available or APC is used.
Cache facade, ApcuStore) and service container, requiring minimal architectural changes. Enables environment-aware activation (e.g., shared hosting vs. self-managed servers) without disrupting existing codebases.session.driver = 'apcu' or object caching). Acts as a compatibility layer to delay costly infrastructure upgrades or codebase refactoring.apcu, redis) via configuration, preventing performance degradation in critical paths. Example:
// config/cache.php
'stores' => [
'apcu' => [
'driver' => 'apcu',
'use_polyfill' => env('APCU_POLYFILL', false),
],
],
Cache events (e.g., CacheStoredEvent) to log polyfill usage or trigger fallbacks (e.g., switch to database cache if polyfill fails). Example:
Cache::extend('apcu', function ($app) {
return new class extends \Illuminate\Cache\ApcuStore {
public function store($key, $value, $ttl = null) {
if (\Symfony\Polyfill\Apcu\ApcuFunctions::isRegistered()) {
Log::debug('APCu polyfill storing: ' . $key);
}
return parent::store($key, $value, $ttl);
}
};
});
apcu_* function calls (e.g., apcu_fetch, apcu_store) work without changes after installation. Ideal for quick wins in shared hosting or legacy environments.composer require symfony/polyfill-apcu.AppServiceProvider or a dedicated provider for centralized control:
// app/Providers/ApcuPolyfillServiceProvider.php
public function register()
{
if (!extension_loaded('apcu') && env('APCU_POLYFILL', false)) {
\Symfony\Polyfill\Apcu\ApcuFunctions::register();
Log::info('APCu polyfill activated');
}
}
Cache::shouldReceive()) and is mockable via PHPUnit. Example:
public function test_apcu_polyfill()
{
if (!extension_loaded('apcu')) {
\Symfony\Polyfill\Apcu\ApcuFunctions::register();
}
Cache::put('test_key', 'test_value');
$this->assertEquals('test_value', Cache::get('test_key'));
}
Cache::remember with short TTLs).config, sessions) via Laravel’s cache tags.config/cache.php to disable polyfill for performance-sensitive stores.file cache for problematic types.serialize()/unserialize() helpers.Laravel-Specific Usage:
apcu, file, database) rely on APCu? Can polyfill be scoped to specific stores?laravel-apcu) requiring integration?Performance Impact:
Environment Strategy:
.env flags, CI/CD pipelines)?Migration Path:
Cache facade, ApcuStore) and service container. No conflicts with Laravel’s core or popular packages (e.g., laravel-debugbar, spatie/laravel-caching).grep -r "apcu_" app/ vendor/ config/
// config/cache.php, config/session.php
composer.json:
{
"require": {
"symfony/polyfill-apcu": "^1.35"
}
}
composer update symfony/polyfill-apcu..env):
APCU_POLYFILL=true
AppServiceProvider:
public function boot()
{
if (!extension_loaded('apcu') && env('APCU_POLYFILL', false)) {
\Symfony\Polyfill\Apcu\ApcuFunctions::register();
Log::info('APCu polyfill activated');
}
}
ApcuStore and can be extended to support custom drivers.apcu) if configured to use APCu.spatie/laravel-activitylog, laravel-horizon). Audit for packages with direct APCu dependencies.\Symfony\Polyfill\Apcu\ApcuFunctions::register();
Log::info('APCu polyfill activated in ' . app()->environment());
memory_get_usage().file cache for complex objects.How can I help you explore Laravel packages today?