Why I have to call 'exit' after redirection through header('Location..') in PHP?

后端 未结 6 1567
刺人心
刺人心 2020-11-22 10:38

You know that if you want to redirect an user in PHP you can use the header function:

header(\'Location: http://smowhere.com\');

It is also

6条回答
  •  抹茶落季
    2020-11-22 11:20

    Without the exit call, the exact point/time at which your script will terminate will come down to two factors:

    1. How quickly the client browser reacts to the redirect
    2. How much time it takes the rest of your script to execute.

    Let's say the browser IMMEDIATELY starts the redirect action the moment it sees the Location header come through. That means it will shut down the connection from which the redirect comes, so it can start connecting to the new location. This generally means the web server will terminate the redirecting script. However long it takes for the header to go from server->client and the TCP link shutdown process to go from client->server is the amount of time in which your script can keep running.

提交回复
热议问题