All Projects → twn39 → LightMoon

twn39 / LightMoon

Licence: other
A framework based swoole

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to LightMoon

Hyperf Skeleton
🛠 A skeleton of Hyperf framework that provided by official team
Stars: ✭ 162 (+852.94%)
Mutual labels:  swoole
Swoole Bundle
Symfony Swoole Bundle
Stars: ✭ 201 (+1082.35%)
Mutual labels:  swoole
Phpdhtspider
php实现的dht爬虫
Stars: ✭ 248 (+1358.82%)
Mutual labels:  swoole
Phwoolcon
Phalcon + Swoole
Stars: ✭ 173 (+917.65%)
Mutual labels:  swoole
Tsf
coroutine and Swoole based php server framework in tencent
Stars: ✭ 2,204 (+12864.71%)
Mutual labels:  swoole
Docker Files
Collection of prooph docker files
Stars: ✭ 232 (+1264.71%)
Mutual labels:  swoole
Swoole
【Swoole 从入门到实战】学习笔记,从零开始学 Swoole,包括 Swoole Task,Swoole WebSocket,Swoole HTTP 服务,Swoole RPC 服务,Swoole MySQL 连接池,Swoole Redis 连接池,Swoole 压测等,其中 7 个源码分享,11 篇总结文章分享。
Stars: ✭ 160 (+841.18%)
Mutual labels:  swoole
docker-images
本仓库为自定义及收藏的一些镜像,方便使用。包含PHP5、PHP7开发环境等镜像。
Stars: ✭ 18 (+5.88%)
Mutual labels:  swoole
Yurunhttp
YurunHttp 是开源的 PHP HTTP 客户端,支持链式操作,简单易用。完美支持Curl、Swoole 协程。QQ群:17916227
Stars: ✭ 197 (+1058.82%)
Mutual labels:  swoole
W7 Rangine Empty
软擎是基于 Php 7.2+ 和 Swoole 4.4+ 的高性能、简单易用的开发框架。支持同时在 Swoole Server 和 php-fpm 两种模式下运行。内置了 Http (Swoole, Fpm),Tcp,WebSocket,Process,Crontab服务。集成了大量成熟的组件,可以用于构建高性能的Web系统、API、中间件、基础服务等等。
Stars: ✭ 246 (+1347.06%)
Mutual labels:  swoole
Php Msf Docs
PHP微服务框架开发手册,即Micro Service Framework For PHP Develop Manual
Stars: ✭ 185 (+988.24%)
Mutual labels:  swoole
Swoft Im
基于swoft-cloud的微服务架构,最小化拆分粒度,PHP7、多进程、协程、异步任务、mysql连接池、redi连接池、rpc连接池、服务治理、服务注册与发现、Aop切面、全注解
Stars: ✭ 189 (+1011.76%)
Mutual labels:  swoole
Zapi
基于swoole的异步轻量级api框架,内部封装全套mysql、redis、mongo、memcached异步客户端,可以轻松start、reload、stop,加入数据库的查询模块,框架已经封装好近乎同步写法,底层异步调用。现已支持异步mysql、异步redis、异步http请求.
Stars: ✭ 245 (+1341.18%)
Mutual labels:  swoole
Connection Pool
A common connection pool based on Swoole is usually used as a database connection pool.
Stars: ✭ 164 (+864.71%)
Mutual labels:  swoole
docker-swoole-webapp
Simple Docker-image to build your applications based on Async PHP extensions.
Stars: ✭ 26 (+52.94%)
Mutual labels:  swoole
Yii2 Swoole
make yii2 project runing on swoole
Stars: ✭ 161 (+847.06%)
Mutual labels:  swoole
Mega Wechat
基于Swoole的微信发送模板消息队列服务
Stars: ✭ 206 (+1111.76%)
Mutual labels:  swoole
swoole-ide-helper-phar
Swoole IDE 自动补全,PHAR 包。
Stars: ✭ 14 (-17.65%)
Mutual labels:  swoole
dwoole
⚙️ Docker image for Swoole apps with Composer, auto-restart on development and a production-ready version.
Stars: ✭ 32 (+88.24%)
Mutual labels:  swoole
Hyperf Admin
hyperf-admin 是基于 hyperf + vue 的配置化后台开发工具
Stars: ✭ 244 (+1335.29%)
Mutual labels:  swoole

LightMoon是一个基于 Swoole 的微型框架,灵感来自于 Slimphp。

设计理念

简单至上,越少的代码意味着越少的 bug,此框架核心代码加上注释不足500行,路由采用 Symfony routing,依赖管理使用 pimple。 不同的项目有不同的需求,有人会使用 MVC 全功能框架,例如 Laravel 来开发整个业务,也有人会使用 Slimphp 这种微型框架来开发 api。 通过pimple很容易将 lightmoon 扩展为全功能框架,也可以仅仅使用核心功能来开发api。

优势

LightMoon 基于 Swoole,因此在性能方面有很大的优势,API借鉴于 Slimphp,熟悉 Slimphp 的用户能够很快上手, 灵活容易定制,甚至可以 fork 本项目修改核心代码来满足业务需求,在能够极大地提升性能的同时,可以利用 php 完整,成熟的生态。

缺点

LightMoon 是基于 swoole,因此需要对 Swoole 有基本的了解。

教程

安装

composer require lightmoon/lightmoon

使用

简单示例

<?php

use Pimple\Container;
use Zend\Config\Config;
use LightMoon\Application;
use Pimple\ServiceProviderInterface;
use LightMoon\Middleware\JsonResponseMiddleware;

require __DIR__.'/vendor/autoload.php';

$config = [
    'server' => [
        'host' => '0.0.0.0',
        'port' => '8060',
        'worker_num' => 2,
    ]
];

class HomeController
{
    public function site($request, $response)
    {
        $response->write(json_encode([
            'title' => 'hello swoole !',
        ]));
        return $response;
    }

    public function api($request, $response, $attr) {
        $response->write(json_encode([
            'version' => $attr['version'],
        ]));

        return $response;
    }
}

class HomeControllerProvider implements ServiceProviderInterface
{
    public function register(Container $container)
    {
        $container[HomeController::class] = new HomeController();
    }
}

$app = new Application(new Config($config));
$app->register(new HomeControllerProvider());
$app->middleware(new JsonResponseMiddleware(), $priority = 10);

$app->get('home', '/', HomeController::class.'@site');
$app->get('api', '/api/{version}', HomeController::class.'@api', [
    'version' => 'v[1-9]+'
]);

$app->run();

middleware

<?php

$app->middleware(function ($request, $response) {
    $response->header('Content-type', "Application/json");
    return $response;
}, $priority = 10);

swoole event

<?php

$app->on('workerstart', function () {
    echo "worker started\n";
});

$app->on('start', function () {
    echo "start....\n";
});

路由

路由支持: GET, POST, PUT, DELETE, PATCH, HEAD,

$app->get('home', '/', 'HomeController@index')

注册组件

创建组建:

use Pimple\Container;

class FooProvider implements Pimple\ServiceProviderInterface
{
    public function register(Container $pimple)
    {
        // register some services and parameters
        // on $pimple
    }
}

注册:

$app->register(new FooProvider());

添加数据库:

LightMoon 提供了 Eloquent ORM 封装,默认并没有启用,如需启用,可添加配置:

$config = [
    'server' => [
        'host' => '0.0.0.0',
        'port' => '8060',
        'worker_num' => 2,
    ],
    'DB' => [
        'driver' => 'sqlite',
        'database' => __DIR__ . '/DB.sqlite',
        'prefix' => '',
        'foreign_key_constraints' => true,
        'pool' => [
            'size' => 3,
        ]
    ],

注入数据库服务:

$app->register(new DatabaseProvider());

注:Eloquent ORM 使用的是 PDO 和 Mysqli, 所以需要开启:Swoole\Runtime::enableCoroutine()

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].