Home  >  Article  >  Backend Development  >  I would like to ask, in the laravel framework, how to monitor the interface api, call frequency and sensitive request parameters?

I would like to ask, in the laravel framework, how to monitor the interface api, call frequency and sensitive request parameters?

WBOY
WBOYOriginal
2016-12-01 00:56:332098browse

<code>http://test.php
method:post
param:{"name":"12333","id":"2"}

需要监控的情况
1.如果用户进行创建数据或更新数据,就要监控
2.对价格进行修改需要监控,然后发有邮件通知接口负责人,"有人修改了商品价格"


目前已经实现了,
request:  uri  method ip port 的记录

param : 请求参数

result 响应接口

user_id 接口请求者</code>

Could you please tell me how to refine the monitoring of this interface, thank you?

Reply content:

<code>http://test.php
method:post
param:{"name":"12333","id":"2"}

需要监控的情况
1.如果用户进行创建数据或更新数据,就要监控
2.对价格进行修改需要监控,然后发有邮件通知接口负责人,"有人修改了商品价格"


目前已经实现了,
request:  uri  method ip port 的记录

param : 请求参数

result 响应接口

user_id 接口请求者</code>

Could you please tell me how to refine the monitoring of this interface, thank you?

I will give a simple answer, the questioner can check the relevant documents by himself

  1. Interface frequency limitation

    • Laravel 5.2 and above comes with throttle middleware control

    • Laravel 5 can be implemented using third-party extension packages https://github.com/GrahamCampbell/Laravel-Throttle

  2. Interface updates can directly monitor Eloquent events, the relevant event document address is https://laravel-china.org/docs/5.1/eloquent#events

    • For example, listen to the saving event of User and determine whether the nickname of User has been modified. The brief code is as follows

    <code>User::saving(function(User $user){
        // 判断昵称是否修改
        if ($user->isDirty('nick_name')) {
            $old_nick_name = $user->getOriginal('nick_name'); // 原始值
            $new_nick_name = $user->nick_name;   // 新值
            Mail::raw("$user->name 把昵称 $old_nick_name 修改为 $new_nick_name"); // 发送邮件
        }
    });</code>
  3. Request parameters, parameter rules rules for each Request can be defined for each interface, and unified interception and processing

Can’t it be implemented in code? If you consider performance, you can just use the message queue
Or add logs and let the OP monitor the logs and send emails accordingly

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Questions sorted by time?Next article:Questions sorted by time?