- What is hyperf/process used for?
- hyperf/process is the process management component for the Hyperf framework. It lets you define custom worker processes with AbstractProcess, run process pools with concurrent workers, handle signals, and shut down or restart workers gracefully. Typical uses include background jobs, queue consumers, and long-running tasks that should run alongside the Swoole server.
- How do I install hyperf/process?
- Install it with composer require hyperf/process. Most Hyperf skeletons already include the component, but you can add it explicitly. Register each process class in config/autoload/processes.php so Hyperf starts it with the server, then restart the service for changes to take effect.
- Does hyperf/process work with Laravel?
- No. hyperf/process is built for the Hyperf framework and the Swoole coroutine runtime, so it will not run inside a standard Laravel application. Laravel developers should use queue workers, Horizon, or a supervisor-managed Symfony Process for similar behaviour. The concepts are similar, but the APIs and lifecycle are not interchangeable.
- How do I create a custom process in Hyperf?
- Create a class that extends Hyperf\Process\AbstractProcess and implement the handle method with your long-running logic. Give the process a name and add the class to config/autoload/processes.php. Hyperf resolves it through the DI container, so you can inject dependencies in the constructor. Keep handle idempotent because the process may be restarted automatically.
- How do I configure process pools and concurrent workers?
- Set the process count with the $nums property or through process pool configuration, and Hyperf will fork that many workers. Use Hyperf\Process\ProcessPool or pool-aware processes when you need shared worker management. Watch memory and connection limits, since each worker is a separate process, and size the pool to your CPU and I/O profile.
- How does graceful shutdown and restart work with signals?
- Hyperf listens for SIGTERM and coordinates shutdown, letting processes finish the current task before exiting. AbstractProcess provides hooks such as isEnable and restart interval settings so a worker can stop and be relaunched. Prefer the framework's stop and start commands over kill -9, which bypasses graceful handling and can leave jobs half-done.
- Which Hyperf and PHP versions does hyperf/process support?
- Version support is defined by the package's Composer constraints, so check them before upgrading. Current releases target modern PHP 8.x and Hyperf 3.x, with older branches for Hyperf 2.x, and require a compatible Swoole or Swow runtime. If you are on Laravel, none of these version constraints apply because the component is Hyperf-only.
- How do I test a custom Hyperf process?
- You can unit test the handle logic by instantiating the process with a mocked container and calling methods directly. For integration tests, boot a Hyperf application and assert that processes register and start without errors. Avoid relying on real signals in CI, and keep long-running loops short-circuit-able so tests do not hang.
- What should I check before running hyperf/process in production?
- Check for memory leaks in long-running loops, set a sensible restart interval, and make sure logs go somewhere durable. Ensure jobs are idempotent because restarts and duplicate workers can occur. Confirm the process does not block the event loop, and avoid running schema migrations from multiple workers at once.
- What are the alternatives to hyperf/process?
- For Hyperf, alternatives include writing raw Swoole processes, using hyperf/crontab for scheduled work, or delegating to Supervisor and Symfony Process. On Laravel the closest equivalents are queue workers, Horizon, and supervisor-managed artisan commands. Choose hyperf/process when you want lifecycle and DI integration managed by the framework itself.