Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Context Laravel Package

hyperf/context

Hyperf/Context provides a coroutine-safe context container for Hyperf applications, letting you store and retrieve request-scoped values without leaking state across coroutines. It offers simple get/set/has APIs and integrates with Hyperf's DI and lifecycle for request data, tracing IDs, and other p...

View on GitHub
Deep Wiki
Context7

A coroutine/application context library.

Frequently asked questions about Context
What is hyperf/context used for?
hyperf/context provides a coroutine-safe, key-value context container for Hyperf applications. It lets you store request-scoped values such as trace IDs, tenant data, or per-request services without leaking state across concurrent coroutines. The API is intentionally small: set, get, has, destroy, and copy. In a Hyperf app on Swoole or Swow it is load-bearing infrastructure used by the HTTP server, DI, and request lifecycle.
Is hyperf/context a Laravel package?
No. hyperf/context is a Hyperf framework component split from the Hyperf monorepo, and it ships no Laravel service provider, facade, config file, or container bindings. It targets Hyperf 3.x running on Swoole 5.x or Swow with coroutines enabled. If you are evaluating it for a Laravel app, the correct target is Illuminate\Support\Facades\Context instead.
Can I use hyperf/context in a Laravel Octane application?
You should not. Octane already provides request sandboxing, and Laravel ships its own Illuminate\Support\Facades\Context with different semantics. Outside an active coroutine the Hyperf context degrades to process-global static storage, which is a correctness trap rather than a feature in an FPM or Octane process. Mixing the two same-named Context classes also creates import confusion.
How do I install hyperf/context?
Run composer require hyperf/context, though any Hyperf 3.x application already has it installed transitively through hyperf/framework and hyperf/di. There is no service provider to register, no config file to publish, and no Laravel container binding to wire up. Verify the resolved version in composer.lock before relying on specific behavior.
Which Laravel versions does hyperf/context support?
None. The package has no Laravel version constraint because it is not built for Laravel; it requires PHP 8.1+ plus a Hyperf 3.x runtime on Swoole 5.x or Swow. Laravel applications should use Illuminate\Support\Facades\Context, which is a same-named but semantically different API.
How do I set and get values with Hyperf\Context\Context?
Use Context::set($key, $value) to store a value for the current coroutine and Context::get($key, $default) to read it back. Context::has($key) checks existence, Context::destroy($key) removes a single key, and Context::copy() copies context state, which is useful when spawning child coroutines. All operations are scoped to the active coroutine when one exists.
Is hyperf/context safe for concurrent requests?
Yes, when it is used inside an active Swoole or Swow coroutine. Values set in one request coroutine are not visible to another, which is exactly what prevents request-scoped state from bleeding between concurrent requests in a long-lived worker. The safety guarantee depends entirely on the coroutine runtime being enabled and the code executing inside the Hyperf request lifecycle.
What happens if I use Context outside an active coroutine?
When no coroutine is active, hyperf/context falls back to process-global storage. That means code which passes in unit tests without a coroutine can behave differently, and sometimes unsafely, under the server. This is the single largest source of works-locally, corrupts-in-production defects with this package. Write integration tests that run inside a coroutine and audit any context access in bootstrapping or CLI code.
Should I use hyperf/context 3.2 beta or stay on 3.1?
For production, pin to the stable 3.1.x line unless you specifically need 3.2 features. The 3.2 line has shipped alpha and beta releases, and beta churn under DI and HTTP handling carries API and behavior drift risk. Also note that standalone repo activity understates real usage because consumers pull hyperf/framework, and issue triage generally happens upstream in the Hyperf monorepo.
How is Hyperf\Context\Context different from Laravel's Context facade?
They are different classes with different semantics despite sharing a name. Hyperf\Context\Context stores values per coroutine and falls back to process-global storage outside a coroutine, while Illuminate\Support\Facades\Context is Laravel's request-scoped context API. In a mixed or migrating codebase, resolve the collision with explicit imports and a lint rule rather than relying on aliases.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
vento/laravel-airbrake
wfeller/laravel-batch
maco-studios/mage-os-installer
busarm/armie
siberfx/laravel-logger
kfteam1991/dcat-admin
dashed/dashed-laposta
dashed/dashed-ecommerce-montaportal
dashed/dashed-ecommerce-etsy
neohq/string-blade-compiler
log1x/acf-composer
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core
nodisrupt/laravel-agent
sierratecnologia/media-manager