Weave Code
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

View on GitHub
Deep Wiki
Context7

A coroutine context library

Frequently asked questions about Context
Can I use hyperf/context in a Laravel application for request-scoped context propagation?
No, hyperf/context is designed for Hyperf, a coroutine-based framework, and won’t work in Laravel. Laravel’s synchronous architecture lacks native coroutine support, making direct integration impossible without significant refactoring. For request-scoped context, Laravel’s built-in middleware or `$request->attributes` are better suited.
What Laravel alternatives exist for context propagation similar to hyperf/context?
Laravel offers native solutions like middleware for request-scoped data (`$request->attributes`) or scoped service bindings (`app()->bindWhen()`). For async workflows, queue jobs with payloads or database-backed context are common. Symfony’s Context Component is another alternative if you’re using Symfony components.
Will hyperf/context work with Laravel if I use Swoole or RoadRunner for async PHP?
No, hyperf/context relies on Hyperf’s coroutine system, which isn’t directly compatible with Swoole or RoadRunner in Laravel. While these tools enable async PHP, they don’t provide the same dependency injection or event loop as Hyperf. For async context, consider Laravel’s queue system or custom middleware instead.
How can I store request-scoped context in Laravel without external packages?
Laravel provides built-in ways to store request-scoped context: use `$request->attributes` to attach data to the request object, or leverage middleware to inject context. For service-level context, `app()->bindWhen()` or `app()->instance()` (with caution) can be used, though these are global rather than request-scoped.
Is hyperf/context worth evaluating for distributed tracing in Laravel?
No, hyperf/context isn’t suitable for Laravel’s distributed tracing needs. Instead, use Laravel-specific tools like OpenTelemetry PHP or middleware to inject trace IDs into requests. These solutions integrate seamlessly with Laravel’s architecture without requiring coroutine support.
Can I polyfill hyperf/context in Laravel to support coroutines?
Attempting to polyfill hyperf/context in Laravel is risky and unsupported. It would require mocking Hyperf’s coroutine system, which isn’t feasible without breaking changes. Laravel’s existing tools (middleware, queue jobs) are more reliable for context propagation without coroutine overhead.
Does hyperf/context support Laravel’s service container or event system?
No, hyperf/context is tightly coupled to Hyperf’s dependency injection and event systems, which are incompatible with Laravel’s. Laravel uses its own service container and event system, so integrating hyperf/context would require rewriting core functionality, making it impractical.
What are the performance implications of forcing hyperf/context into Laravel?
Forcing hyperf/context into Laravel would introduce unnecessary performance overhead due to coroutine emulation in a synchronous environment. Laravel’s middleware or request attributes are optimized for its architecture and won’t add the same latency risks. Coroutines in Laravel would only make sense with PHP fibers or a coroutine-compatible server like RoadRunner.
Are there any Laravel packages that provide similar functionality to hyperf/context?
No direct equivalents exist, but packages like `spatie/laravel-activitylog` (for request-scoped logging) or custom middleware can achieve similar goals. For async context, consider `spatie/laravel-queue-short-circuiting` or database-backed solutions. Symfony’s Context Component is a closer alternative if you’re using Symfony components in Laravel.
Should I wait for PHP 8.1+ fibers or RoadRunner to use hyperf/context in Laravel?
Even with PHP fibers or RoadRunner, hyperf/context won’t integrate natively due to its Hyperf-specific design. Instead, focus on Laravel-compatible async solutions like queue workers or middleware. Monitor RoadRunner’s context APIs for future alignment, but hyperf/context itself won’t be a drop-in replacement.
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.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor