Category: Coding
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…
PHP 模拟 RSA 算法
从 1-10 中间任意取两个 质素 p 和 q 让 p*q = n funN = (p-1) * (q-1) 获取 公钥 e: – 1 < e < funN– e 和 funN 互质 获取 私钥 d:使得 (e * d) % funN = 1 任意拿一个数字 m 用公钥匙 e 对其加密:pow(m, e) % n = c,c 即加密后的信息 用私钥 d 对c 解密:pow(c, d)…
How to output variable in Nginx for debugging
You can send Nginx variable values via headers. Handy for development. and you’ll see in your browser’s response headers:
JWT authentication for Lumen
参考:https://medium.com/tech-tajawal/jwt-authentication-for-lumen-5-6-2376fd38d454 1.Add JWT_SECRET=xxxx to yours.env file 2. Create a migration file for the users table: 3. Modify the migration file created inside the database/migrations directory 4. create the seeder to populate the database with some users. Modify database/seeds/UsersTableSeeder.php to look like: 5. Now create the configured database in MySQL and run the following commands inside your terminal to create…
使用 Intervention Image (PHP Package)修改图片大小
Intervention Image 是一个PHP图像处理和操作库,提供了一种更简单、更富表现力的方法来创建、编辑和组合图像。该包包括 ServiceProviders 和 Facades,便于Laravel集成。 这儿只是描述使用这个包来做一些最常用的图片截取调整大小的操作。 安装 例子 关于 调整大小 fit – 裁剪和调整大小相结合 resize – 调整大小
如何用 Kubernetes 来部署一个 PHP 应用 到 阿里云
根据 原文 结合阿里云改编。 前言 Introduction Kubernetes是一个开源的容器编制系统。它允许您创建、更新和扩展容器,而无需担心停机。 要运行一个PHP应用程序,Nginx充当PHP- FPM的代理。将此设置装入一个容器可能是一个很麻烦的过程,但是Kubernetes可以帮助在分开的容器中管理这两个服务。使用Kubernetes将允许您保持容器的可重用性和可切换性,并且您不必每次有新版本的Nginx或PHP时都重新构建容器映像。 Step 1 — 创建 PHP-FPM 和 Nginx 服务 在这个步骤,你将创建 PHP-FPM 和 Nginx 服务,在这个集群里,一个服务可以访问一组 pods,集群里的服务可以直接通过他们的 名字 来通讯,不需要 IP 地址。PHP-FPM 服务可以访问 PHP-FPM 的pods,Nginx 服务可以访问 Nginx pods。 由于Nginx pods将代理PHP-FPM pods,您需要告诉服务如何找到它们。您将利用Kubernetes的自动服务发现,使用人类可读的名称将请求路由到服务而不是使用IP地址。 要创建服务,您将创建一个对象定义文件。每个Kubernetes对象定义都是一个YAML文件,其中至少包含以下内容: apiVersion: The version of the Kubernetes API that the definition belongs to. kind: Kubernetes 对象. 例如, a pod or service. metadata: This…
Allow CORS in Laravel or Lumen
首先创建一个中间件,lumen 需要手动创建 更新 app/Http/Middleware/Cors.php Laravel: 注册中间件到 app/Http/kernel.php Lumen: 修改 bootstrap/app.php 最后,您想要启用CORS的任何路由,只需在路由注册中添加此中间件。 Laravel, add test routers in routes/api.php Lumen:
HTTP Status code in REST API
请求方式 HTTP Methods HTTP methods are sometimes referred to as HTTP verbs. They are simply just different ways to communicate via HTTP. The main ones used by the REST API are: GET should be used for retrieving data from the API. POST should be used for creating new resources (i.e users, products, taxonomies). PUT should…
PHP multi-dimensional array sort
From: http://php.net/manual/en/function.usort.php Example #4 usort() example using a closure to sort a multi-dimensional array You can also sort multi-dimensional array for multiple values like as:
Vue: Using localStorage with Vuex store
This tutorial uses Vue v2.4.4 and Vuex v2.5.0 – although I’m sure it will work with previous versions localStorage basics# localStorage is a cache in the browser which persists even after the browser is closed. It allows you to store data on a page and later access it – it’s especially easy to do using JavaScript.…
自动设置内容里的第一张图片为特色图片,并上传到Aliyun OSS
本文章测试于 WordPress 4.4.2 这儿需要用的两个插件 阿里云附件存储 [http://yii.im/posts/aliyun-oss-support-plugin-for-wordpress] Auto Post Thumbnail [https://wordpress.org/plugins/auto-post-thumbnail/] 接下来 要对 auto post thumbnail 里的函数 apt_generate_post_thumb 稍作修改,将文件下载保存在本地替换成使用 wp_handle_sideload 上传到OSS /** * Function to fetch the image from URL and generate the required thumbnails */ function apt_generate_post_thumb($matches, $key, $post_content, $post_id) { // Make sure to assign correct title to the image. Extract it from img…