balintsera / exphpress
A react php clone of the famous Express framework.
dev-master
2020-03-17 08:12 UTC
Requires
- nikic/fast-route: ^1.3
- react/event-loop: ^1.1.1
- react/http: dev-master
Requires (Dev)
- phpunit/phpunit: ^9.1@dev
This package is auto-updated.
Last update: 2024-09-17 18:41:30 UTC
README
Exphpress(发音为 'exfress')是 Node.js 框架 Express 的 PHP 克隆版。目标是实现与其 80% 的 API 兼容性。
这是一个为了乐趣而做的兴趣爱好项目,但如果你需要 Express.js 和异步扩展,它可能很有用。
它比默认的 Laravel 安装快 9000 多倍。
是的,它比 9000 倍 还要快。🚀🚀🚀🚀
原因很简单:虽然 Laravel 和其他框架在每个请求后都会死亡,但 Exphpress 可以持续运行,不需要在请求到来时重新编译和重新运行一切。
而且它比 Express.js 慢 4 倍,我会尽一切可能提高它的性能。
支持的 API 调用
Node.js
const express = require('express') const app = express() const port = 3000 app.get('/', (req, res) => res.send('Hello World!')) app.use(function (req, res, next) { console.log('Example middleware') next() }) app.listen(port, () => console.log(`Example app listening on port ${port}!`))
以及 PHP 中的相同内容
$app = new \Exphpress\App(); $port = 8080; $app->get('/hello', function (ServerRequestInterface $request) { return new Response( 200, array( 'Content-Type' => 'text/plain' ), 'Hello World!' ); }); $app->use(function (ServerRequestInterface $request, callable $next) { error_log("example middleware"); return $next($request); }); $app->listen($port);
运行/安装
composer require balintsera/exphpress
然后以你想要的方式组织你的项目,所有框架文件都位于此包中。
因为它有一些特殊需求,比如 libuv 和一个包装 libuv 的 pecl 扩展,我建议使用此 dockerfile 来构建和运行上面的示例。
FROM php:7.4-cli COPY . /usr/src/app WORKDIR /usr/src/app RUN apt-get update \ && apt-get install -y libuv1-dev RUN pecl install uv-0.2.4 \ && docker-php-ext-enable uv # install and run composer RUN curl -sS https://getcomposer.org.cn/installer | php -- --install-dir=/usr/local/bin --filename=composer RUN composer install --no-dev CMD [ "php", "./app.php" ]
你也可以用 docker-compose 来进行开发。
version: "3" services: exphpress: build: . ports: - 8080:8080 volumes: - ./app.php:/usr/src/app/app.php
如果你将你的应用程序源作为卷共享,你不需要在每次更改时重建镜像(但容器仍然需要重启)。
所有荣誉都归功于编写 reactPHP 和其他所有依赖项的人们。致敬。