简体   繁体   English

CakePHP 3 Rest API

[英]CakePHP 3 Rest API

I'm implementing an API using CakePHP3 with a MySQL database.我正在使用带有 MySQL 数据库的 CakePHP3 实现 API。

Everything works fine.一切正常。 The endpoints are a secured with a Basic Authentication.端点使用基本身份验证进行保护。

Now I have noticed that the performance is dreadful.现在我注意到表演很糟糕。 I started some speed tests with loader.io and noticed that the response times are around 400ms.我开始使用 loader.io 进行一些速度测试,并注意到响应时间约为 400 毫秒。

I don't know why, but at one point i deactivated the AuthComponent of CakePHP and suddenly I only had a response time of 120ms.我不知道为什么,但有一次我停用了 CakePHP 的 AuthComponent,突然我的响应时间只有 120 毫秒。

So I started digging around.于是我开始四处挖掘。 I then implemented my own BasicAuthentication by just reading the header and comparing the user & password with my users table in the database.然后,我通过读取标题并将用户和密码与数据库中的用户表进行比较来实现我自己的 BasicAuthentication。 I still have ~120ms response time.我仍然有大约 120 毫秒的响应时间。 Is the CakePHP3 AuthComponent just bloated up? CakePHP3 AuthComponent 只是膨胀了吗? I also noticed while having the AuthComponent activated that my php-fpm uses a large amount of CPU.我还注意到,在激活 AuthComponent 时,我的 php-fpm 使用了大量 CPU。 Without The AuthComponent it's practicly nothing.没有 AuthComponent,它实际上什么都不是。

I implemented the BasicAuth exactly as described in the CakePHP Documentation.我完全按照 CakePHP 文档中的描述实现了 BasicAuth。 I just don't know what is going on.我只是不知道发生了什么。 I would prefer to use the actual CakePHP methods than implementing my own check.我更愿意使用实际的 CakePHP 方法而不是实现我自己的检查。 Has anybody else ever had this issue?有没有其他人遇到过这个问题? I just don't understand what is going on.我只是不明白发生了什么。

at last we found out what was causing the lond response times.最后,我们发现了导致响应时间过长的原因。 It wasn't the AuthComponent but more the DefaultPAsswordHasher.它不是 AuthComponent,而是更多的 DefaultPAsswordHasher。

I wrote a new PasswordHasher (for testing purposes returning the password unhashed) and the speed went up by factor 3.我写了一个新的 PasswordHasher(出于测试目的,返回未散列的密码),速度提高了 3 倍。

In config/app.phpconfig/app.php

Set 'debug' = false;设置'debug' = false;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM