Can you give some more information? Show the controller code for registration
My Registration Process is so slow [ 5 : 9 seconds ]
I have a registration form where I collect register information, then
1- Send Welcome mail 2- Verify Mail 3- Insert a value into another table 4- insert another value into another table
Then redirect the customer to welcome page.
in the Network Console "Register" has a very big waterfall and it takes from 5 to 9 seconds to process. when I clicked on it, like css and js files in addition to connection to facebook fbevent and google recaptcha.
I even have a loader GIF, which doesn't even appear to the customers on registration.. it only appear after the registration is processed just before going to welcome page. So when the customer click on Register.. nothing happen for like 9 seconds, then the loading gif just appear and redirection happen and all is good to go.
I tried to remove the " Emails " and the data insertions from the RegisterController, but that didn't change anything, the speed was same. so apparently it's not the mail and insertions that are causing the delays. any tips on how to speed this generally or at least figure out exactly what is causing all this delay :) ?? would appreciate your help.
Hello @gitwithravish .. here you are the full code .. just for you to know, I removed the google recaptcha, facebook pixels , google analytics and even the payment gateway script from my header. but none of these helped fasten the process, or even show any signs of improvement. in the network console, when I looked at the initiators, there are a bunch of css and js being called, but none of them exceeds a few ms. or has a significant waterfall. only Register.
I even removed the whole controller and replaced it with the original default register controller of laravel. but still same results. Actually my Register process was fast before, but I remember as I'm adding features, I was like okk fine will get back to this later on. and noww I have no idea what is causing all this delay.
<?php
namespace App\Http\Controllers\Auth;
use Request;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use App\User;
use App\Contact;
use App\Wallet;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Mail;
use App\Rules\PhoneNumber;
use App\Rules\FullName;
use App\Mail\WelcomeMail;
use GuzzleHttp\Client;
use Session;
class RegisterController extends Controller
{
use RegistersUsers;
protected $redirectTo = '/verifyemail';
public function __construct()
{
$this->middleware('guest');
}
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:30', new FullName],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
'phone' => ['required', new PhoneNumber],
'birthdate' => ['required'],
]);
}
protected function create(array $data)
{
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
'phone' => $data['phone'],
"birthdate"=>$data['birthdate'],
'ip' => request()->ip(),
]);
Mail::to($user->email)->send(new WelcomeMail());
Contact::create([
'user_id' => $user->id,
]);
Wallet::create([
'user_id' => $user->id,
]);
return $user;
$captchatoken = $request->input('g-recaptcha-response');
if ($captchatoken) {
$client = new Client();
$response = $client->post('https://www.google.com/recaptcha/api/siteverify', [
'form_params' => array(
'secret' => '6Ldo-uEZAAAAAMFKTnYpJAbazolD3n0JPFQJrXsf',
'response' => $captchatoken
)
]);
$results = json_decode($response->getBody()->getContents());
}
if ($results->success) {
} else {
Session::flash('error', 'You are probably a robot!');
return redirect('/');
}
}
}
is the create process being delayed by your
Mail::to($user->email)->send(new WelcomeMail());
if you switch mail driver to log or comment that step out does that speed anything up?
Hello @automica .. not at all .. i even removed the mail entirely .. and removed the insertions .. didn't even improve anything .. the delay was also experienced by my friend on live so it's not related to my machine or work environment.
ok so you need to step through it.
User::create looks like it should be quick.
What does Contact::create do?
What does Wallet::create do?
- Are you getting any slowness on normal page loads for your site?
- What sort of response times do you have for welcome page?
- Are you connecting to a DB locally to your development environment?
- How are you running your development environment? Windows / Wamp / Lamp? / Mamp? / Docker/ Homestead?
@automica .. Contact and wallet creates new entries for the new user in these two tables. so that later on for example he can edit his social contacts [contacts] and I can give him points in the [ wallet ]. deleting these two insertion did not make any improvements. otherwise, I would have removed them entirely.
1-almost all app pages load time is between 250 to 500 ms .. not bad for me.
2- the welcome page loading time is 261 ms / which is pretty ok for me as well.
3- Sometimes Inserting a new comment also took long. that's why I even added the loader gif, to give the customers any hints that something is loading .. this does not even happen on registration. as the loading gif only appears after the registration is done.
4- I didn't quite understand the question, sorry. but I have a database on localhost and i manage it through php my admin on local machine.
4- my web hosting is Digital ocean Lamp Ubuntu on Ubuntu 20 with apache2 .. php my admin for database management and I use visual studio as SSH and sometimes WinSCP.
@mahmoudmonem are load times 5 -> 9 seconds only on your local server or on your remote as well?
@automica on remote as well .. only Register takes that long .. even asked a friend to try ... to make sure that it's not related to cache or anything on my machine or browser. same thing
if you comment out your validation, does that speed anything up?
I notice you have
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
do you have an index on your email field? how many users do you have in your database? what does your PhoneNumber validator do?
I removed all the validations except for name didn't improve anything..
Removed the Phone number field entirely and it's validation .. same 9.4 s :D
The phone Rule is there to make sure that the phone input customers put is valid phone number in Egypt and not any gibberish
return preg_match('/^[0-9]{3}[0-9]{8}$/', $value) && strlen($value) >= 10;
and this is my Email input
<div class="col-sm-12">
<div class="form-group">
<!-- <label for="email">E-mail Address</label> -->
<input id="email" class="form-control" type="email" placeholder="Email - البريد الإلكتروني" name="email" value="{{ old('email') }}" required autocomplete="email">
<p class="font-size-sm text-muted mb-4 text-left">A verification message will be sent to this Email</p>
@error('email')
<span class="invalid-feedback" role="alert">
<strong>Your Email is Wrong or Taken</strong>
</span>
@enderror
</div>
</div>
Btw I don't have any users in the database as I didn't launch the website .. so like 4 5 users ..
how are you specifying database host in .env? Are you using localhost or an ip address?
@automica The ip address 127.0. etc db port 3306 in both local and server
@mahmoudmonem if you install Laravel/ debugbar you might be able to get some more info about whats causing the issue.
Alright will install and check it out .. Thank you @automica for the help and time, really appreciated :)
Please or to participate in this conversation.