walkor / webman Goto Github PK
View Code? Open in Web Editor NEWProbably the fastest PHP web framework in the world.
Home Page: https://webman.workerman.net/
License: MIT License
Probably the fastest PHP web framework in the world.
Home Page: https://webman.workerman.net/
License: MIT License
原来
Worker::$onMasterReload = function (){
foreach (array_keys(opcache_get_status()['scripts']) as $file) {
opcache_invalidate($file, true);
}
};
改成
Worker::$onMasterReload = function (){
if(opcache_get_status()){
foreach (array_keys(opcache_get_status()['scripts']) as $file) {
opcache_invalidate($file, true);
}
}
};
经过这个方式进行处理,强迫症发作。。。
我测试了
post数据是这样
map_id=102&item_id=274&mine_power=3&cur_energy=11409&cur_cache_power=-3&request_time=1603102417234
和post数据是这样
map_id=102&item_id=69&mine_power=18&unlock_fog_new=1&fog_data=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAQEBAQEBAQAAAAEAAAEBAQEBAQEBAQEBAQEBAQEBAQICAQAAAQEBAQEAAQEAAAECAgICAgICAgICAgICAgICAgIBAAAAAAAAAAABAgEAAAECAgICAgICAgICAgICAgICAgICAQAAAAAAAAAAAQEAAAECAgICAgICAgICAgICAgICAgICAgEAAAAAAAAAAQEAAAECAgICAgICAgICAgICAgICAgICAgEAAAAAAAAAAQEAAQICAgICAgICAgICAgICAgICAgICAgIBAAAAAQABAgEAAAECAgICAgICAgICAgICAgICAgICAgIBAAAAAQECAgEAAAECAgICAgICAgICAgICAgICAgICAgEAAAAAAAECAgEAAAECAgICAgICAgICAgICAgICAgICAgEAAAAAAAACAgEAAAECAgICAgICAgICAgICAgICAgICAgEAAAAAAAABAgEAAAECAgICAgICAgICAgICAgICAgICAgEAAAAAAAABAgEAAAECAgICAgICAgICAgICAgICAgICAgIBAAAAAAECAQAAAAECAgICAgICAgICAgICAgICAgICAgEBAAAAAQICAgEAAAECAgICAgICAgICAgICAgICAgICAQAAAAAAAQICAgEAAAECAgICAgICAgICAgICAgICAgIBAAAAAAAAAAECAgEAAAECAgICAgICAgICAgICAgICAgICAQAAAAAAAAECAgIBAAECAgICAgICAgICAgICAgICAgICAgEBAAAAAAECAgEAAAECAgICAgICAgICAgICAgICAgICAgEAAAAAAAECAgEAAAECAgICAgICAgICAQICAQEBAgEBAQEAAAAAAQICAgEAAAECAgICAgICAgIBAAEBAAAAAQAAAAAAAAAAAQICAgEAAAECAgICAgICAgEAAAAAAAAAAAAAAAAAAAAAAQICAgEAAAECAgICAgICAgEAAAAAAAAAAAAAAAAAAAAAAQICAgEAAAECAgICAgICAgEAAAAAAAAAAAAAAAAAAAAAAQICAgEAAAECAgICAgICAgIBAAAAAAAAAAAAAAAAAAAAAAECAgEAAAECAgICAgICAgICAQAAAAAAAAAAAAEAAAAAAAECAgEAAAECAgICAgICAgICAgEAAAAAAAAAAAEBAAAAAQICAgEAAAECAgICAgICAgICAgIBAQAAAAAAAQICAQEBAgICAQEAAAECAgICAgICAgEBAQEBAQEBAQEBAQEBAQEBAQEBAAAAAAEBAQEBAQEBAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA&cur_energy=11577&cur_cache_power=-18&request_time=1603102346563
的时候,处理时间会有明显的差别,后面的至少会比前面的慢4倍左右.
你好,首先恭喜workerman在最近的techempower框架压测中超过swoole。
最近注意到有个基于workerman的框架comet ,是把SlimPHP直接和workerman结合了起来,请问webman和这种方式的区别是什么?能否通过直接整合现有成熟框架的方式加快webman开发?
最后,问下webman有没有计划什么时候发布正式版?
原生的,要如何解决共同部分的问题那。
array_keys() expects parameter 1 to be array, null given in file start.php on line 28
Invalid argument supplied for foreach() in file /start.php on line 28
it's show every time the code changes
比如 自定义进程
、队列
等
还有路由中间件貌似不支持。
crontab 任务怎么解决好呢?
目前是这么解决的
public function onWorkerStart()
{
Timer::add(60, function(){
if(date('H:i') === '08:00') {
…………
}
});
}
建议:可以采用casbin和layui-mini(xadmin等等)做一个RABC的后台管理系统来推广此框架,相信使用的同行会越来越多。
指向public下面的静态文件配置,之前的WebServer可以配置$web->addRoot('127.0.0.1:55151' , DIR.'/../../public/');//指引网站的目录
现在的这个版本没有这个指向了,难道只能在nginx里面去做转发吗?
作者您好,可以分享下webman项目后续的版本规划吗?
报的是找不到opcache_get_status()错误,服务无法启动,安装完opcache后,一切正常,建议加个判断或者提醒。
Blade模板引擎 按照文档安装包配置后,不能正常工作
app 目录下新建了api文件夹,通常还会有子级v1、v2、目录这些,这种时候有没有方法只需要简单的配置路由就能访问到相应的控制器
由于采用ftp同步代码,使用的是本地开发+服务器预览的模式,因此存在2台电脑之间的时间差异,本地时间总是在一天内快过服务器端几十秒,所以在服务器端的FileMonitor类监控文件修改的时候,就会出现“差异的秒数”导致不断reload,具体日志打印如下:
/www/wwwroot/webman/process/FileMonitor.php=>1599643353---1599643359
/www/wwwroot/webman/process/FileMonitor.php update and reload
Workerman[start.php] reloading
/www/wwwroot/webman/process/FileMonitor.php=>1599643354---1599643359
/www/wwwroot/webman/process/FileMonitor.php update and reload
Workerman[start.php] reloading
/www/wwwroot/webman/process/FileMonitor.php=>1599643356---1599643359
/www/wwwroot/webman/process/FileMonitor.php update and reload
Workerman[start.php] reloading
/www/wwwroot/webman/process/FileMonitor.php=>1599643357---1599643359
/www/wwwroot/webman/process/FileMonitor.php update and reload
Workerman[start.php] reloading
/www/wwwroot/webman/process/FileMonitor.php=>1599643358---1599643359
/www/wwwroot/webman/process/FileMonitor.php update and reload
Workerman[start.php] reloading
其中第一行我是加的调试本次问题的打印日志,有2个时间戳,第一个时间戳是 $last_mtime ,第二个时间戳是当前文件的修改时间变量 $file->getMTime() ,FileMonitor 类主要就是对比这2个时间戳来决定是否需要 reload。
由于每次对比发现修改了文件后,都需要 reload ,所以 static $last_mtime; 这一句以及对比成功后赋值 $last_mtime = $file->getMTime(); 实际上无法生效,导致每次对比文件 reload 后都执行了:
if (!$last_mtime) {
$last_mtime = time();
}
因此就出现了上面那一段调试日志的情况,$last_mtime 每隔1秒增加,直到大于等于 $file->getMTime() 才会停下来,因此,我建议在每次对比成功之后,修改当前文件的“修改时间”属性为当前服务器时间,来避免这种情况发生,优化后的代码如下:
(一共三处,以 woeoio 注释开头)
public function check_files_change($monitor_dir)
{
//woeoio:调试发现由于每次修改后都是 reload 的,所以此处的 static 其实没有实际意义。
// static $last_mtime;
// if (!$last_mtime) {
$last_mtime = time();
// }
clearstatcache();
if (!is_dir($monitor_dir)) {
return;
}
// recursive traversal directory
$dir_iterator = new \RecursiveDirectoryIterator($monitor_dir);
$iterator = new \RecursiveIteratorIterator($dir_iterator);
foreach ($iterator as $k => $file) {
/** var SplFileInfo $file */
if (is_dir($file)) {
continue;
}
// check mtime
if ($last_mtime < $file->getMTime() && in_array($file->getExtension(), $this->_extensions)) {
$var = 0;
exec("php -l ".$file, $out, $var);
if ($var) {
//woeoio:重新赋值变量的改为重新修改文件的时间属性
// $last_mtime = $file->getMTime();
touch($file);
continue;
}
echo $file." update and reload\n";
// send SIGUSR1 signal to master process for reload
posix_kill(posix_getppid(), SIGUSR1);
//woeoio:重新赋值变量的改为重新修改文件的时间属性
// $last_mtime = $file->getMTime();
touch($file);
break;
}
}
}
以上是关于监控类的一个使用场景的优化建议,对于本机开发和调试的场景,不存在这个情况,,但是对于本机开发异地调试的场景,确实很有必要,因为时间差异多少秒,进程就会 reload 多少次,希望采纳,谢谢。
很多应用中只会用到一种或几种,能不能把数据库支持的驱动做成外挂库。
需要用的的时候 composer require 安装进去
DB::table('users')->where('votes', '>', 100)->dd();
DB::table('users')->where('votes', '>', 100)->dump();
使用不了报错
For Authentication purposes, usually In Codeigniter can create extends
<?php
namespace app\controller;
use app\controller\Auth\Auth;
use support\Request;
class Index extends Auth {
So in Auth add constructor to check if session username exists, else redirect to login
It's make easier for admin module Authentication
I did try it but doesn't work
初始安装后运行:php start.php start -d
出现如下错误,原因是runtime文件夹下没有log文件夹,无法自动创建stdout.log,所以建议初始配置 config/server.php/stdout_file = runtime_path() . '/stdout.log',或者runtime文件夹下添加log文件夹,方便初次使用的人运行测试。
Fatal error: Uncaught Exception: Can not open stdoutFile /mnt/d/website/webman/runtime/log/stdout.log in /mnt/d/website/webman/vendor/workerman/workerman/Worker.php:1256
Stack trace:
#0 /mnt/d/website/webman/vendor/workerman/workerman/Worker.php(1527): Workerman\Worker::resetStd()
#1 /mnt/d/website/webman/vendor/workerman/workerman/Worker.php(1371): Workerman\Worker::forkOneWorkerForLinux()
#2 /mnt/d/website/webman/vendor/workerman/workerman/Worker.php(1345): Workerman\Worker::forkWorkersForLinux()
#3 /mnt/d/website/webman/vendor/workerman/workerman/Worker.php(546): Workerman\Worker::forkWorkers()
#4 /mnt/d/website/webman/start.php(30): Workerman\Worker::runAll()
#5 {main}
thrown in /mnt/d/website/webman/vendor/workerman/workerman/Worker.php on line 1256
场景 :在控制器中使用Db Db类中需要使用请求参数,这个请求参数只能使用传参才能得到么
原"vlucas/phpdotenv": "^4.1" 无问题
新拉取版本变为"vlucas/phpdotenv": ">=4.1,<6.0" getenv() env() 获取不到.env配置
框架的 env() 需要 将Dotenv::createMutable(base_path())->load() 变为 Dotenv::createUnsafeImmutable(base_path())->load()才能获取
composer.json中也没配置
For workerman it's easy, but how about webman?
Steps to recreate error:
Create a get route
Create a post route
Send a body of {"test": "test"} as application/json
Start server and run get requests -> 200 OK
Quit server, start again and run post requests -> 200 OK
Start server and run get request -> 200 OK
Run post request -> 400 bad request
Run post request again -> 200 OK on all subsequent requests
Does not occur with an empty body on post.
Thanks.
Usually add
header('Content-Encoding: gzip');
in native php
But I did modify in core or add in return still not working
return new Response(200, ['Content-Encoding' => 'gzip'], "Hello World");
And show error on browser
Content Encoding Error
Please we need Gzip Encoding for better compression and faster response
在本地 WSL上调试的时候,使用 http://127.0.0.1:8787/ 访问,无论如何刷新页面都不会出现bug。
放到远程上去之后,用nginx做了反向代理,然后通过
http://47.105.106.73:8787/ 和 http://bigtran.opmonitor.com/ 这两个来访问,都会间歇性的出现这三个bug
1、首页的第一个bug,这个_siteInfo() 是通过 config/autoload.php 引入的
Error: Call to undefined function _siteInfo() in /root/webman/translog/public/_theme/default/inc/header.php:1 Stack trace: #0 /root/webman/translog/public/_theme/default/index.php(4): require() #1 /root/webman/translog/support/view/TransLogTheme.php(39): include('/root/webman/tr...') #2 /root/webman/translog/support/helpers.php(169): support\view\TransLogTheme::render() #3 /root/webman/translog/app/controller/Index.php(14): view() #4 /root/webman/translog/vendor/workerman/webman-framework/src/App.php(140): app\controller\Index->index() #5 /root/webman/translog/vendor/workerman/workerman/Connection/TcpConnection.php(660): Webman\App->onMessage() #6 /root/webman/translog/vendor/workerman/workerman/Events/Select.php(293): Workerman\Connection\TcpConnection->baseRead() #7 /root/webman/translog/vendor/workerman/workerman/Worker.php(2417): Workerman\Events\Select->loop() #8 /root/webman/translog/vendor/workerman/workerman/Worker.php(1542): Workerman\Worker->run() #9 /root/webman/translog/vendor/workerman/workerman/Worker.php(1372): Workerman\Worker::forkOneWorkerForLinux() #10 /root/webman/translog/vendor/workerman/workerman/Worker.php(1346): Workerman\Worker::forkWorkersForLinux() #11 /root/webman/translog/vendor/workerman/workerman/Worker.php(542): Workerman\Worker::forkWorkers() #12 /root/webman/translog/start.php(136): Workerman\Worker::runAll() #13 {main}
2、继续刷新首页,还会出现这个 NotFoundException
Webman\Exception\NotFoundException: Class 'support\exception\Handler' not found in /root/webman/translog/vendor/workerman/webman-framework/src/Container.php:53 Stack trace: #0 /root/webman/translog/vendor/workerman/webman-framework/src/App.php(186): Webman\Container->make() #1 /root/webman/translog/vendor/workerman/webman-framework/src/App.php(170): Webman\App::exceptionResponse() #2 /root/webman/translog/vendor/workerman/workerman/Connection/TcpConnection.php(660): Webman\App->onMessage() #3 /root/webman/translog/vendor/workerman/workerman/Events/Select.php(293): Workerman\Connection\TcpConnection->baseRead() #4 /root/webman/translog/vendor/workerman/workerman/Worker.php(2417): Workerman\Events\Select->loop() #5 /root/webman/translog/vendor/workerman/workerman/Worker.php(1542): Workerman\Worker->run() #6 /root/webman/translog/vendor/workerman/workerman/Worker.php(1372): Workerman\Worker::forkOneWorkerForLinux() #7 /root/webman/translog/vendor/workerman/workerman/Worker.php(1346): Workerman\Worker::forkWorkersForLinux() #8 /root/webman/translog/vendor/workerman/workerman/Worker.php(542): Workerman\Worker::forkWorkers() #9 /root/webman/translog/start.php(136): Workerman\Worker::runAll() #10 {main}
3、打开 这两个页面的时候,偶尔会404,刷新之后又没有了
http://bigtran.opmonitor.com/achieves
http://bigtran.opmonitor.com/article/hello-translog
是环境问题?一样的composer install的vendor文件。
Just Like Codeigniter or any other php framework, they have Helper / Library for custom function & library
function allowTags($text) {
$tags = '<strong><h1><h2><h3><h4><br><hr><b><ol><ul><u><span><li><a><img><iframe>';
return strip_tags(html_entity_decode(trim($text)), $tags);
}
for example I create multiple Controller and want to call the function allowTags()
in any controller
我看数据库配置很简单 暂时没有实现连接池功能吧
跨域必须 Route::any()这样
位置:support/middleware/StaticFile.php
行:27
return response('<h1>403 forbidden</h1>', [], 403);
应为:
return response('<h1>403 forbidden</h1>', 403, []);
支持PHP5.3吗 支持异步编程吗 支持PHP5.4吗
一直用workman,很稳定,无意间看到这款框架,准备用来开发新项目。新项目有用到主动推送到客户端websocket,现在这款框架支持同时监听其他端口,用来为websocket服务吗
I see the documentation is only single view
return view('dashboard', ['request' => $request]);
How if i wanna add header & footer in Raw view ?
希望框架可以同时支持 php-fpm 及 WorkerServer。
目前大部分环境依然是 ng|ap,也有需要 php 能独立完成 web整套服务的框架。
当前我也有这种需要,基于Workerman+ThinkPHP v6也有做一套应用,但总体不太理想,原因是TP有些地方在Command运行时问题很多,不方便进行二次调整!希望 webman可以在这方面做得更好。
如果 webman 可以二者运行模式兼备,相信框架发展会更好!!!
Cookie: PHPSID=aa2c209ccbced74103da6f01
在session配置没找到, 想知道怎么实现让sessionId 不返回到cookie,想用sessionid当唯一来做前后端分离token
webman有类似请求上下文的那种吗
如题,在开发过程中数据库事件监听还是很有必要的!
首先感谢作者做出贡献,另外东西很好。一系列的产品都很完美!期待
比较实用的有,
thinkphp Auth
laravel spatie/laravel-permission
php casbin (https://github.com/php-casbin)
大佬可以抽空搞下么?
假如Index控制器,如下:
public function __construct($name)
{
$this->name = $name;
}
webman App类在分发路由的时候代码如下:
$app = $controller_and_action['app'];
$controller = $controller_and_action['controller'];
$action = $controller_and_action['action'];
$callback = static::getCallback($app, [static::$_container->get($controller), $action]);
//建议这里通过反射处理下controller构造函数有参数的情况
static::$_callbacks[$key] = [$callback, $app, $controller, $action];
list($callback, $request->app, $request->controller, $request->action) = static::$_callbacks[$key];
static::send($connection, $callback($request), $request);
webman中自带Container类的get方法代码如下,没考虑控制器构造函数有参数的情况:
public function get($name)//构造函数无参数情况
{
if (!isset($this->_instances[$name])) {
if (!class_exists($name)) {
throw new NotFoundException("Class '$name' not found");
}
$this->_instances[$name] = new $name();
}
return $this->_instances[$name];
}
所以会报错,个人建议作者大大,可以考虑把这种虽然比较少用的情况也考虑优化进去
#9 {main}
Error: Class 'Illuminate\Events\Dispatcher' not found in /home/haidar/public_html/test/bench/webman/support/bootstrap/db/Laravel.php:47
Stack trace:
#0 /home/haidar/public_html/test/bench/webman/start.php(59): support\bootstrap\db\Laravel::start()
#1 /home/haidar/public_html/test/bench/webman/vendor/workerman/workerman/Worker.php(2397): {closure}()
#2 /home/haidar/public_html/test/bench/webman/vendor/workerman/workerman/Worker.php(1537): Workerman\Worker->run()
#3 /home/haidar/public_html/test/bench/webman/vendor/workerman/workerman/Worker.php(1367): Workerman\Worker::forkOneWorkerForLinux()
#4 /home/haidar/public_html/test/bench/webman/vendor/workerman/workerman/Worker.php(1341): Workerman\Worker::forkWorkersForLinux()
#5 /home/haidar/public_html/test/bench/webman/vendor/workerman/workerman/Worker.php(1674): Workerman\Worker::forkWorkers()
#6 /home/haidar/public_html/test/bench/webman/vendor/workerman/workerman/Worker.php(1623): Workerman\Worker::monitorWorkersForLinux()
#7 /home/haidar/public_html/test/bench/webman/vendor/workerman/workerman/Worker.php(544): Workerman\Worker::monitorWorkers()
#8 /home/haidar/public_html/test/bench/webman/start.php(130): Workerman\Worker::runAll()
The composer setting is
"require": {
"php": ">=7.2",
"workerman/webman-framework": "^1.0",
"monolog/monolog": "^2.0",
"vlucas/phpdotenv": "^5.1",
"illuminate/database": "^8.0"
},
How to fix it ?
如果其中一个进程死了,没有触发docker的重启
docker-compose.yml
version: "3"
services:
http:
...
deploy:
replicas: 2
restart_policy:
condition: always
...
networks:
- test
networks:
test:
Dockerfile
...
CMD ["php","-d","memory_limit=512M","start.php","start"]
想请教一下,一个静态文件的请求过程是怎样的?调用了哪些文件?最后返回这个静态文件。
cookie设置不生效,求正确姿势
Error: Class 'Illuminate\Redis\RedisManager' not found in D:\webProject\workerman\webman\support\bootstrap\Redis.php:39
解决方式:
composer require illuminate/redis
对于push不太熟,希望作者把这个库添加到composer json中。谢谢。
Db::beginTransaction();
try {
……
Db::commit();
return json(['code' => 0, 'msg' => '通过', 'data' => $data]);
} catch (\Throwable $e) {
Db::rollBack();
return json(['code' => -100, 'msg' => $e->getMessage()]);
}
没有报错 但是数据库没有插入
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.