Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
O

one

> 数据库
Open source

A minimalist high-performance php framework that supports the [swoole | php-fpm] environment

875 stars0 likes1 views
WebsiteGitHub

About

A minimalist high-performance php framework that supports the [swoole | php-fpm] environment

English | 中文

One - A minimalist high-performance php framework that supports the [swoole | php-fpm] environment

  • Fast - can respond to requests within 1ms even under php-fpm
  • Simple - let you focus on what you do with one instead of how to use one
  • Flexible - each component is loosely coupled, can be flexibly matched and used, and the method of use is consistent
    • Native sql can be used with model relation with, relation can cross database types
    • session can be used under http, websocket or even tcp, udp and cli
    • ...
  • High efficiency - operational performance, development efficiency, and easy maintenance.
  • Lightweight - no other dependencies, the total code amount of all components from routing and orm does not exceed 500k. If there is no complicated calling relationship in secondary development, you can quickly grasp the design principle
  • Sub-database and sub-table - Supports wireless sub-database and table, and the upper-layer usage method remains the same

hello world

install

bash
composer create-project lizhichao/one-app app
cd app
php App/swoole.php 

# stop : `php App/swoole.php -o stop`  
# reload : `php App/swoole.php -o reload`  
# Daemon start : `php App/swoole.php -o start`  

curl http://127.0.0.1:8081/

performance

reference:

  • test1 (mysql + orm)
  • test2

Main components

  • Router
    • Support greedy matching and priority
    • Support ws/tcp/http……any protocol
    • Good performance, adding tens of thousands of routes will not reduce the parsing performance
    • Routing grouping, middleware...all there should be
  • ORM
    • Support database: mysql, clickHouse,
    • Relation processing: one-to-one, one-to-many, many-to-one, polymorphism... There are various relations, which can be related across database types
    • Cache: Automatically refresh data, support configuration of various cache granularities
    • Event: All operations can be captured, including you use native SQL to operate the database
    • Database connection: synchronous, asynchronous, blocking, disconnection and reconnection are all supported
    • sql template: automatically generate template id, you can understand what types of sql the project has, and the proportion of the number of calls, and provide data support for later data optimization.
    • Statement reuse: Provide SQL execution performance
    • The model supports dynamic sub-database sub-table and massive data
  • rpc
    • Can automatically generate remote method mapping, support ide prompt
    • Direct call mapping method == call remote method, support chain call
    • Support rpc middleware, authentication, encryption and decryption, caching...
  • Log
    • Complete information: record the complete file name + line number to quickly locate the code location
    • requestId: You can easily view the entire request log information and service relationship

Router

…

orm

Define the model

php
namespace App\Model;

use One\Database\Mysql\Model;

// There is no need to specify the primary key in the model, the framework will cache the database structure
// Automatically match the primary key, automatically filter the fields in the non-table structure
class User extends Model
{
	// Define the table name corresponding to the model
    CONST TABLE = 'users';

	// define relationship
    public function articles()
    {
        return $this->hasMany('id',Article::class,'user_id');
    }
    
    // define event
    // Whether to enable automatic caching
    // ……
}

Use model

  • The database connection is a single column under fpm,
  • All database operations are automatically switched to connection pool in swoole mode
php
// Query a record
$user = User::find(1);

// Related query
$user_list = User::whereIn('id',[1,2,3])->with('articles')->findAll()->toArray();

// update
$r = $user->update(['name' => 'aaa']);
// or
$r = user::where('id',1)->update(['name' => 'aaa']);
// $r To influence the number of records

Cache

php
// Set cache without expiration time
Cache::set('ccc',1);

// Set the cache to expire in 1 minute
Cache::set('ccc',1,60);

Cache::get('ccc');

// or cache ccc expires 10s under tag1
Cache::get('ccc',function (){
    return 'info';
},10,['tag1']);

// Refresh all caches under tag1
Cache::flush('tag1');

HTTP/TCP/WEBSOCKET/UDP

Start a websocket server, Add http service monitoring, Add tcp service monitoring

…

RPC

Call the method of the remote server like the method of this project. Cross language, cross machine.

Service

Start the rpc service. The framework has built-in rpc services for each protocol, just add it to the action in the above configuration file. For example: support http call, and support tcp call.

…

Add specific services to rpc, For example, there is a class Abc

php

class Abc
{
    private $a;

    public function __construct($a = 0)
    {
        $this->a = $a;
    }

    public function add($a, $b)
    {
        return $this->a + $a + $b;
    }

    public function time()
    {
        return date('Y-m-d H:i:s');
    }

    public function setA($a)
    {
        $this->a = $a;
        return $this;
    }
}

Add Abc to rpc service

…

Client call

In order to facilitate the call, we create a mapping class (one framework can be automatically generated)

php
class ClientAbc extends RpcClientHttp {

    // rpc server address
    protected $_rpc_server = 'http://127.0.0.1:8082/';

    // The remote class is not set and the default is the current class name
    protected $_remote_class_name = 'Abc';
}

The remote method of calling the rpc service is the same as the method of calling this project. You can imagine this method is in your project.

php
$abc = new ClientAbc(5);

// $res === 10
$res = $abc->add(2,3);

// Chain call $res === 105
$res = $abc->setA(100)->add(2,3);

// If the User of the above model is added to rpc
// RpcServer::add(User::class);
// The following operation results are the same as above
// $user_list = User::whereIn('id',[1,2,3])->with('articles')->findAll()->toArray();

The above is called through the http protocol. You can also call through other protocols. For example, Tcp protocol

php
class ClientAbc extends RpcClientTcp {

    // rpc server address
    protected $_rpc_server = 'tcp://127.0.0.1:8083/';

    // The remote class is not set and the default is the current class name
    protected $_remote_class_name = 'Abc';
}

The classes RpcClientHttp and RpcClientTcp are in the framework. You can also copy it to any other place for use.

more

  • Various protocol communication examples
  • rpc examples
  • Actor examples

Document

  • Document
  • Parameter validator

TODO

  • support Workerman
  • orm support postgresql

My other open source projects

  • nsq client
  • clickhouse tcp client

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHPframeworkoneormphp

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库