Answer the question
In order to leave comments, you need to log in
Why does the API take so long to respond?
Hello. At the moment, api is being done on a local average power machine. To add a user (registration, that is), I use the same RegisterUser model as on the site. As a result, the method looks like this:
public function actionCreate()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$data=(array)json_decode(Yii::$app->getRequest()->getRawBody());
$newUser=new RegisterForm();
$newUser->attributes=$data;
$registerResult=$newUser->register();
/*В методе register возвращается помимо true/false id созданного пользователя, поэтому массив*/
if ($registerResult["success"]) {
Yii::$app->response->statusCode = 201;
Yii::$app->response->headers->add("Location","/api/user/".$registerResult["id"]);
return "";
}
else {
Yii::$app->response->statusCode = 409;
return $newUser->errors;
}
}
Answer the question
In order to leave comments, you need to log in
1. Is this all the code that is being used? Show what you have in the form of the register method? Maybe there is some complex cycle - no one guesses.
2. Where does it start to slow down for you? On production? Then the problem is most likely in the server itself. There may be some pitfalls. For example, php version, mysql. Compare local setup and production configuration. For example, if you use php7.2 on the local, and php5.6 on production, then the difference is very big in speed. But that's unlikely, of course. Also see if OPCache is enabled. In general, there are many nuances here
. Update the packages on the production server. composer update --no-dev . This command will disable packages that are needed for development (tests, Fixtures). It shouldn't affect much, but the work will be a little faster.
Also, check if the prod
3 constant is on the production server. If it slows down on the local one, then maybe here. Since in development mode a lot of resource-intensive debugging works.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question