
Fiber::getCurrent와 getCurrentContext는 Laravel의 Fiber를 사용할 때 중요한 개념입니다.
Fiber::getCurrent는 현재 실행 중인 Fiber 객체를 반환합니다. Fiber는 비동기 처리를 위한 스레드 안전한 Context를 제공하는 객체입니다.
getCurrentContext는 현재 실행 중인 Fiber의 Context를 반환합니다. Context는 Fiber 내부에서 사용하는 데이터를 저장하는 객체입니다.
둘의 차이점은 Fiber 객체와 Fiber의 Context를 가져오는 것입니다. Fiber::getCurrent는 Fiber 객체 자체를 가져오고, getCurrentContext는 Fiber의 Context를 가져옵니다.
예를 들어, 다음 코드를 살펴보겠습니다.
#hostingforum.kr
php
use IlluminateSupportFacadesFacade;
$context = Facade::getFacadeRoot()->app->make('context');
$context->set('key', 'value');
$context = Facade::getFacadeRoot()->app->make('context');
echo $context->get('key'); // value
$context = Facade::getFacadeRoot()->app->make('context');
echo $context->get('key'); // value
위 코드에서 Facade::getFacadeRoot()->app->make('context')는 getCurrentContext를 호출한 것과 같습니다.
Fiber::getCurrent를 사용하면 다음 코드와 같습니다.
#hostingforum.kr
php
use IlluminateSupportFacadesFacade;
$context = Facade::getFacadeRoot()->app->make('context');
$context->set('key', 'value');
$context = Facade::getFacadeRoot()->app->make('context');
echo $context->get('key'); // value
$context = Facade::getFacadeRoot()->app->make('context');
echo $context->get('key'); // value
Fiber::getCurrent를 사용하면 Fiber 객체를 가져와 Context를 가져올 수 있습니다.
getCurrentContext를 사용하면 Fiber의 Context를 직접 가져올 수 있습니다.
둘의 차이점은 Fiber 객체와 Fiber의 Context를 가져오는 것입니다. Fiber::getCurrent는 Fiber 객체 자체를 가져오고, getCurrentContext는 Fiber의 Context를 가져옵니다.
이러한 차이점을 이해하면 Laravel의 Fiber를 사용할 때 더 효율적으로 Context를 관리할 수 있습니다.
2025-06-03 12:00