As an alternative for Siler, something lightweight and simple that works as a library with Swoole out-of-the-box, I highly recommend Nano! Check it out: https://nano.hyperf.wiki/#/en/
Siler is a set of general purpose high-level abstractions aiming an API for declarative programming in PHP.
Files and functions as first-class citizens
Zero dependency, everything is on top of PHP built-in functions
Blazing fast, no additional overhead - benchmark 1, benchmark 2 and benchmark 3
Flat files and plain-old PHP functions rocking on a production-grade, high-performance, scalable, concurrent and non-blocking HTTP server.
Read the tutorial.
composer require leocavalcante/siler
That is it. Actually, Siler is a library, not a framework (maybe a micro-framework), the overall program flow of control is dictated by you. So, no hidden configs or predefined directory structures.
use SilerFunctional as λ; // Just to be cool, don't use non-ASCII identifiers ;)use SilerRoute;Routeget('/', λputs('Hello, World!'));Nothing more, nothing less. You don't need even tell Siler to run or something like that (puts works like a lazily evaluated echo).
use SilerRoute;use SilerHttpResponse;Routeget('/', fn() => Responsejson(['message' => 'Hello, World!']));The Responsejson function will automatically add Content-type: application/json in the response headers.
Siler provides first-class support for Swoole. You can regularly use Route, Request and Response modules for a Swoole HTTP server.
use SilerHttpResponse;use SilerRoute;use SilerSwoole;$handler = function () {Routeget('/', fn() => Responsejson('Hello, World!'));
};$port = 8000;echo "Listening on port $portn";Swoolehttp($handler, $port)->start();Install peer-dependency:
composer require webonyx/graphql-php
type Query {hello: String}use SilerRoute;use SilerGraphQL;$type_defs = file_get_contents(__DIR__ . '/schema.graphql');$resolvers = ['Query' => ['hello' => fn ($root, $args, $context, $info) => 'Hello, World!']
];$schema = GraphQLschema($type_defs, $resolvers);Routepost('/graphql', fn() => GraphQLinit($schema));Another peer-dependency:
composer require doctrine/annotations
Then:
/** * @SilerGraphQLAnnotationObjectType() */final class Query
{/** * @SilerGraphQLAnnotationField() */public static function hello($root, $args, $context, $info): string{return 'Hello, World!';
}
}use SilerGraphQL;use SilerRoute;$schema = GraphQLannotated([Query::class]);Routepost('/graphql', fn() => GraphQLinit($schema));Object type name will be guessed from class name, same for field name, and it's return type (i.e.: PHP string scalar === GraphQL String scalar).
Documentation
Examples
MIT license
Copyright 2020 © LC