개발자 Q&A

개발하다 막혔다면? 여기서 질문하세요! 초보부터 고수까지, 함께 고민하고 해결하는 공간입니다. 누구나 자유롭게 질문하고 답변을 남겨보세요!

2025.06.03 12:00

Fiber::getCurrent와 getCurrentContext의 차이점

목록
  • 메모리최적화전문가 오래 전 2025.06.03 12:00
  • 64
    1
제가 공부하던 도중 Fiber::getCurrent와 getCurrentContext라는 용어를 접하게 되었는데, 둘의 차이점을 모르겠어요. Fiber::getCurrent는 현재 Fiber를 가져오는 것일까요? 그리고 getCurrentContext는 어떤 Context를 가져오는 것일까요? 둘의 차이점을 알려주세요.

    댓글목록

    profile_image
    나우호스팅  오래 전



    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

  • 개발자 Q&A 포인트 정책
      글쓰기
      50P
      댓글
      10P
  • 전체 37,809건 / 16 페이지

검색

게시물 검색