Download the PHP package kekke/mononoke without Composer
On this page you can find all versions of the php package kekke/mononoke. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package mononoke
Mononoke
⚠️ Early Alpha Notice
Mononoke is currently in early alpha and under active development.
Features, and implementations may change at any time without notice.
It is not yet recommended for production use, but feedback and contributions are welcome.
Mononoke is a PHP microservice framework and utility toolkit built with modern PHP practices.
It leverages Swoole for an asynchronous HTTP server and the AWS SDK for SNS and SQS integration,
allowing you to build event-driven, scalable PHP applications.
Installation
Via composer:
composer require kekke/mononoke
https://packagist.org/packages/kekke/mononoke
Features
-
AWS SNS and SQS Integration
Manage SNS topics, send notifications, subscribe queues, and poll SQS messages asynchronously. -
Swoole HTTP Server
Asynchronous HTTP server with FastRoute-based routing for defining HTTP endpoints via PHP attributes. -
WebSockets
Real-time, bidirectional communication between clients and the server, powered by Swoole’s WebSocket server. -
Background Tasks
Offload blocking or long-running work to Swoole’s task workers for efficient non-blocking request handling. - Scheduler
Register cron-like scheduled tasks using attributes.
Attribute-based Listeners
Mononoke uses PHP attributes to register HTTP routes, WebSocket event handlers, scheduled tasks, background tasks, and SNS/SQS message handlers.
This allows for a clean and declarative service definition.
Example Service
Available attributes
1. Http
Define HTTP routes directly on service methods with the Http attribute.
Usage
- Route methods can return:
string→ returned astext/plain(200)array→ returned asapplication/json(200, JSON-encoded)GuzzleHttp\Psr7\Response→ returned as-is
- Typical definition:
Supported HTTP methods
Tip: If your
Httpattribute accepts the enum, you may useHttp(HttpMethod::GET, '/health')instead of a string literal.
2. Schedule
Register cron-like scheduled tasks with the Schedule attribute. Some schedules require extra parameters (hour/minute/second). Helper methods on the enum indicate what is required.
Basic usage
Time-specific examples (if supported by your attribute signature)
Available scheduler options
Notes:
- For modes that “require” hour/minute/second, supply those via your
Scheduleattribute’s parameters (named arguments are recommended if supported).- If you omit a required component, validation should fail early (consider adding validation in your attribute or setup logic).
3. AwsSnsSqs
Subscribe a method to an SNS topic (via an SQS queue) with the AwsSnsSqs attribute. The framework will provision the SNS topic/SQS queue (if needed), subscribe them, and poll messages.
Usage
DLQ
Using a DLQ is possible via the dlqName parameter in the AwsSnsSqs attribute.
When using a DLQ, the message will be handled and if an uncaught exception is thrown while handling the message, send the message to the DLQ after dlqMaxRetryCount retries.
You can adjust the retries using the config;
Guidelines
- Make handlers idempotent; SQS may deliver messages at-least-once.
- Handle failures and consider dead-letter queues (DLQ) in your AWS setup.
- Keep handlers fast; offload long-running work if possible.
4. WebSockets
Create a websocket server using the WebSocket attribute.
Usage
5. Tasks
Create background workers using the task interface
Usage
To dispatch a new task, use (new BackgroundTask($this->server))->dispatch('task_name', ['message' => 'Hello World!']); and then make sure that setup a task handler using the Task attribute.
Config
You can adjust several options using the Config attribute in Mononoke.
To get started, attach a Config attribute to your Service class, the Config attribute then accepts 3 different configs that you may adjust to your liking.
Usage
Available options can be discovered by peeking into the 3 different config classes;
MononokeConfig, AwsConfig & HttpConfig.
Status
Mononoke is actively evolving. Expect rapid iteration, breaking changes, and new features as the framework stabilizes.
Contributions, bug reports, and feedback are highly appreciated!
License
This project is licensed under the MIT License.
It also makes use of third-party libraries under their respective licenses, including:
- AWS SDK for PHP (Apache License 2.0)
- Swoole IDE Helper (Apache License 2.0)
- nikic/fast-route (MIT)
- monolog/monolog (MIT)
- phpstan/phpstan (MIT)
- phpunit/phpunit (MIT)