octane: Swoole + `defer()`, function already exists.
Laravel Version
11.23.4
PHP Version
8.3.10
Database Driver & Version
mysql5.7:latest docker
Description
Laravel Sail v1.32.0.
When using the Cache::flexible() method I get the following error:
defer() expects exactly 1 argument, 2 given at /var/www/html/vendor/laravel/framework/src/Illuminate/Cache/Repository.php:521)
I noticed this error only happens in the browser not the CLI - which I usually run form my host, not sail/docker. So I tried it in the sail container - same error.
So dumping a reflection of the function reveals:
$reflFunc = new ReflectionFunction('defer');
dd($reflFunc);
1 ReflectionFunction {#4 ▼
+name: "defer"
returnType: "void"
parameters: {▼
$callback: ReflectionParameter {#19 ▼
+name: "callback"
position: 0
typeHint: "callable"
}
}
extra: {▼
extension: "swoole"
isInternal: true
}
}
Printing phpinfo() shows that Sail has Swoole installed. and I assume from this Swoole adds a global defer() function, so the Lavavel helper funciton is never defined - and would error if it did - when Swoole is installed.
Steps To Reproduce
Create a new Laravel 11.23+ project using Laravel Sail (or install Swoole).
run a controller or tinker:
// call it twice
Cache::flexible('test', [1, 5], fn () => 'test');
Cache::flexible('test', [1, 5], fn () => 'test');
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (4 by maintainers)
deferis a short named function in swoole that you can turn off via php.ini.Fixed via https://github.com/laravel/framework/pull/52801
So why install it with Sail?
Hello,
I use Forge Laravel Octane is disabled
I’m trying to use
Cache::flexible()And get this error:
I assume that Forge pre-installs Swoole (so that it is always ready to be turned on) … and as a result there is a naming conflict
@marco-silvestri Swoole is included in sail, I’ve managed to fix it by doing the following
./docker/php/sail-php.iniRunning into this issue on an upgraded Laravel 11 project with Sail, where Swoole is clearly installed by default:
/docker/8.3/Dockerfile:33-34
&& pecl install swoole-5.1.2 \ && echo "extension=swoole.so" > /etc/php/8.3/cli/conf.d/20-swoole.ini \I believe the
deferfunction name is already registered with theSwooleextension, which could cause conflicts with existing projects that rely on Swoole’s defer function or have the Swoole extension enabled. Unfortunately, I think Laravel should consider renaming the defer function to avoid these conflicts.