Octane Version
2.13.1
Laravel Version
12.38.1
PHP Version
8.4.14
What server type are you using?
Swoole
Server Version
nginx
Database Driver & Version
No response
Description
When registering a singleton via AppServiceProvider, the constructor is triggered only once per worker, as expected. However, when using the attribute-based singleton registration (https://laravel.com/docs/12.x/container#singleton-attribute
), the constructor appears to be triggered once per request scope, behaving more like a scoped service. This may be due to the sandbox being registered earlier.
Steps To Reproduce
Check running this part
namespace App\TestService;
use Illuminate\Container\Attributes\Singleton;
#[Singleton]
class TestService
{
public function __construct()
{
echo("__construct TestService");
echo(spl_object_id($this));
}
}
in some controler use
app(\App\TestService\TestService::class);
app(\App\TestService\TestService::class);
app(\App\TestService\TestService::class);