- What is barbushin/laravel-swoole-jsonrpc used for?
- It is a lightweight bridge that lets a Laravel application expose its services as JSON-RPC 2.0 remote procedures while running on the Swoole extension. The package handles request parsing, method routing and dispatch, and Swoole server execution so you can serve RPC endpoints from persistent, coroutine-friendly workers instead of a classic PHP-FPM request cycle. It fits internal service-to-service APIs and high-throughput endpoints that reuse existing Laravel code.
- How do I install barbushin/laravel-swoole-jsonrpc?
- Install it with Composer using composer require barbushin/laravel-swoole-jsonrpc. You also need the Swoole PHP extension available in the environment that runs the workers, since the package depends on Swoole's server runtime. After installing, register the package's service provider if your Laravel version does not auto-discover it, then publish and adjust the package configuration.
- Which Laravel and PHP versions are supported?
- The package targets Laravel applications running on the Swoole extension, so your PHP build must include Swoole at a version your runtime supports. Exact Laravel and PHP constraints are declared in the package's composer.json, and that file is the authoritative source rather than the README. Check it before upgrading Laravel or PHP and test on your target runtime, because Swoole compatibility is usually the limiting factor.
- How do I register a callable RPC method?
- Methods are registered through the package's service provider and configuration integration, where you map an RPC method name to a callable handler. The handler can be a closure, an invokable class, or a controller-style action that returns the result payload for the JSON-RPC response. Incoming calls are parsed and routed to that handler automatically, so you only maintain the mapping and the method logic itself.
- How do I configure the package?
- Configuration is published from the package into your Laravel config directory, where you set the server options and the method mappings used by the JSON-RPC dispatcher. Because Swoole workers run outside the normal HTTP kernel, values such as host, port, and worker counts live in this configuration alongside your RPC registrations. Keep environment-specific values in your .env file and cache the config as you would for any Laravel package.
- Does it handle JSON-RPC 2.0 parsing and responses, including batches and notifications?
- The package provides JSON-RPC 2.0 request and response handling, so method calls arrive as standard JSON-RPC payloads and results or errors are returned in the matching envelope. Batch requests and notifications are part of the JSON-RPC 2.0 specification, but you should confirm the exact level of support in the package source for your version. If you depend on batching, add an integration test that sends a batch payload and asserts the response shape.
- Can I protect RPC methods with authentication or middleware?
- Yes. The package is designed around a middleware-friendly architecture, so authentication, authorization, and input validation can run before a method is dispatched. Register your middleware in the package configuration or alongside the RPC method registration so unauthenticated calls are rejected with a JSON-RPC error instead of reaching your handler. This keeps auth concerns out of individual method implementations.
- What should I watch out for with Swoole's persistent workers and coroutines in production?
- Swoole keeps workers alive between requests, so anything stored in a singleton or static property can leak across calls, and per-request state should never live on long-lived services. Database connections, caches, and other resources must be coroutine-safe and reset where necessary, and you should verify that Laravel container bindings do not capture stale request data. Load test with realistic concurrency and monitor worker memory growth over time.
- How do I test JSON-RPC methods without running a full Swoole server?
- Test the handler logic directly by resolving the registered callables from Laravel's container in a normal PHPUnit or Pest test, which covers your business logic without Swoole. For end-to-end coverage, start the RPC server in a test process and send real JSON-RPC payloads over HTTP, asserting on both result and error envelopes. Keep a small set of these integration tests, because Swoole-specific behavior cannot be reproduced in a standard feature test.
- How does it compare to Laravel Octane or a dedicated JSON-RPC package?
- This package is narrow by design: it wires JSON-RPC 2.0 dispatch and method registration into a Swoole server rather than changing how the whole framework boots. Octane is a broader solution for serving Laravel on Swoole or RoadRunner, but it does not give you JSON-RPC envelopes or RPC method mapping out of the box. Choose this package when your API contract is JSON-RPC, and choose Octane when you mainly want faster conventional HTTP handling.