- How do I install hyperf/memory?
- Install it with Composer using composer require hyperf/memory. In a Hyperf application the component is discovered through its ConfigProvider, so you can create or publish the memory configuration and then inject the managers via the container. Make sure the Swoole extension is installed and enabled for the runtime.
- What is hyperf/memory used for?
- It provides lightweight shared-memory utilities for Hyperf applications, wrapping Swoole Table and Atomic primitives with configuration-driven managers. Use it to share data and counters safely across worker processes without running an external service such as Redis. It is intended for fast, in-process shared state rather than durable storage.
- Does hyperf/memory work with Laravel?
- No, hyperf/memory is built for Hyperf, which is a coroutine-based PHP framework that uses Swoole and its own DI container. It is not a drop-in Laravel package and does not use Laravel's service providers or facades. If you are on Laravel, you would need a different approach or a Swoole integration layer.
- How do I configure Swoole Tables in hyperf/memory?
- Tables are defined in configuration and created by the component's manager, so you typically declare table names, sizes, and columns in the Hyperf memory config file. The manager then creates or retrieves those table instances through dependency injection. Check the package source or README for the exact config keys because they are not shown in the provided excerpt.
- Which PHP, Swoole, and Hyperf versions does hyperf/memory support?
- The provided context does not list specific version constraints, so you should check the package composer.json before installing. It requires the Swoole extension and a compatible Hyperf version, because it wraps Swoole Table and Atomic directly. Verify the constraints against your application's PHP and Hyperf versions.
- Is hyperf/memory safe to use across coroutines and worker processes?
- Swoole Table is designed to share data across worker processes, and Atomic counters provide lock-free, concurrency-safe increments. The component is described as coroutine-friendly and lightweight, but you must still design your data access carefully around Swoole Table's row-level semantics. It is not a general-purpose database and does not provide transactions.
- Can I use hyperf/memory for atomic counters and rate limiting?
- Yes, the Atomic manager exposes Swoole Atomic counters for concurrency-safe increments without locks. That makes it suitable for simple counters, statistics, and lightweight rate-limiting patterns inside a Hyperf service. Remember that these counters are in memory and reset when the process or server restarts.
- How do I test code that depends on hyperf/memory?
- Because the component depends on Swoole Table and Atomic, tests generally need the Swoole extension and a runtime that supports it. Use Hyperf's testing utilities and coroutine-aware test setup, or mock the manager interfaces for unit tests. Integration tests are the best way to verify cross-worker behavior.
- What are alternatives to hyperf/memory for shared state?
- Common alternatives include Redis or another external cache for durable shared state, APCu for simple local caching, or using Swoole Table directly without the manager wrapper. Hyperf's cache component can also handle shared data when you need persistence or cross-service access. Choose based on whether you need speed and locality or durability and distribution.
- Is hyperf/memory production-ready and maintained?
- It is part of the Hyperf package ecosystem and is intended for production Hyperf services that already use Swoole. Check the repository's release history and issue tracker for maintenance activity, because the provided context does not include repository details. Since shared memory is ephemeral, plan for process restarts and avoid treating it as persistent storage.