Author: 迎迎 姚
A simple API Gateway in Lumen
如何使用 Lumen 开发一个简单的 API Gateway Routes create a file called gateway.php in config folder. Register gateway to lumen routes. Edit AppServiceProvider.php in app/Providers/ folder. Controller AppServiceProvider will send all request to GatewayController. So create GatewayController.php in app/Http/Controllers to handle requests. Middleware Update Authenticate middleware to handle Auth. Update Authenticate.php in app/Http/Middleware folder. 或者,使用角色认证 role middleware.…
PHP 冒泡算法
没什么用,写了玩玩的。 function bubble_sort(array $items): array { for ($i = 0; $i < count($items); $i++) { for ($j = $i + 1; $j < count($items); $j++) { if ($items[$i] > $items[$j]) { $temp = $items[$i]; $items[$i] = $items[$j]; $items[$j] = $temp; } } } return $items; } print_r(bubble_sort([5, 3, 1, 2, 7]));
Laravel/Lumen Customizing Monolog For Channels
官方文档 https://laravel.com/docs/6.x/logging#creating-monolog-handler-channels 首先 新建一个 文件: 如官方文档所示,可以在 __invoke 方法里定制你的 logger,例如你想要 json 格式的日志的话: 更多设置: 输出的日志样本如下: { “message”: “Undefind method: \”asdasdad\””, “context”: {}, “level”: 400, “level_name”: “ERROR”, “channel”: “local”, “datetime”: “2020-05-11T17:05:07.231673+08:00”, “extra”: { “user_id”: “guest”, “roles”: “NULL”, “process_id”: 13, “url”: “/data/v1/download?action=asdasdad&token=1”, “ip”: “172.25.0.1”, “http_method”: “GET”, “server”: “_”, “referrer”: null, “memory_usage”: “2 MB”, “file”: “/var/www/html/app/Http/Controllers/DownloadController.php”, “line”: 69, “class”: “App\\Http\\Controllers\\DownloadController”,…
Multiple middleware parameters in Lumen
Add route middleware in bootstrap/app.php To middleware to routes within a group, Use “,” separate roles, don’t use “|” as separater, the tutorial from here https://docs.spatie.be/laravel-permission/v3/basic-usage/middleware/ is for Laravel only Create a Role Middleware in App\Http\Middleware folder. …$roles in the handler function can accept multiple roles
HTTP Public Key Pinning 公钥固定介绍
文件名 内容 chain.pem 浏览器需要的所有证书但不包括服务端证书,比如根证书和中间证书 fullchain.pem 包括了cert.pem和chain.pem的内容 privkey.pem 证书的私钥 cert1.pem或cert.pem 服务端证书 添加以下行并插入适当的 pin-sha256 =“…”的值将在您的nginx上启用HPKP
Nginx fastcgi_cache And proxy_cache
FastCGI Cache Example FastCGI Cache VS WP Super Cache FastCGI cache is faster than WP Super Cache because the latter uses .htaccess and PHP itself to route the visitor to the cache (files). So before the visitors get to a hit on a cached page, WP Super Cache has to perform some logic both in…