How to fix a slow the job header?

Is the index file is the form action on this form anyway check.php
require_once 'connection.php';
 $login = $_POST['login'];
 $email = $_POST['email'];
 $pass = $_POST['pass'];
 $pas_con = $_POST['pass2'];
 if($pass === $pas_con && $pass != "){
 $passw = md5($pass);
 $query = $conn->prepare("INSERT INTO users(login, email, password) VALUES(?, ?, ?)");
 $query->execute([$login, $email, $passw]);
 $_SESSION['message'] = 'Registration was successful! You can now log in to your account.';
 header("Location: /");

 $_SESSION['message'] = 'the Passwords do not match!';
 header("Location: /");

There is a redirection to the index to give an alert that the registration was successful or not
Why I header? And how is it possible ispraviti? Or is there a way to reduce forwarding?
April 19th 20 at 12:15
3 answers
April 19th 20 at 12:17
echo '<meta http-equiv="refresh" content="0;URL=/">';
no not working - frankie.Gulgowski10 commented on April 19th 20 at 12:20
Oh, God, where are you going then?
Well, because he pants are still confused, take a step can't - and there, to answer with a straight face - gonzalo.Kihn commented on April 19th 20 at 12:23
@gonzalo.Kihn, if you come you can know the answer? - frankie.Gulgowski10 commented on April 19th 20 at 12:26
April 19th 20 at 12:19
Not likely to slow the header!
In the connection settings to the database to change localhost to and then the database connection will not take ~ 1 second.
How to check? Zakommentirovat to work with a DB file if all will be good - then the problem is a slow connection to DB.
//$query = $conn->prepare("INSERT INTO users(login, email, password) VALUES(?, ?, ?)");
//$query->execute([$login, $email, $passw]);
April 19th 20 at 12:21
You have no problem with the slow operation of header(), and inhibits something else.
For example, what may slow down in the provided code:
1. session_start (lock or brake disc if the session file)
2. connection to the database from connection.php
3. queries to the database (insert)
4. lag script / where is the redirect and it seems that the long answer
5. inhibits the web server in principle (TTFB)

If you still think that it hinders the header()
We would like to see the metrics (screenshot) where you can see the fact of braking (waterfall is dev tools of the browser). For example, the same script where there is nothing but <?php header("Location /"); vs script which inhibits

Find more questions by tags PHP