here is a simple script I’ve tested:
<?php
require 'dbcon.php';
header("location:http://google.com");
$time1 = time();
for($i=0;$i<=9999999;$i++){
$j += $i * $i * $i * $i;
}
$time2 = time();
$total = $time2-$time1;
mysql_query("insert into test values('$total')");
?>
this script takes about 15 seconds to execute ( so 15 is inserted in my test table ) and after these seconds , the page redirects too the specified domain.
my question is why this happens?
in my real code, I want to redirect user to a webpage and then execute remaining code and store in database, so the user doesn’t have to wait a lot. how would it be done?
UPDATE1:
please answer this question:
i want to first redirect the user , then insert data to mysql. for example i first get user’s ip. then i want to redirect him , then detect user country from his ip and so on , then insert information into mysql. is it possible in someway?
UPDATE2:
i want to get user’s country and region from another site with curl extension and then store in database. so it takes some seconds…
header("Location: ...");just sets a header, nothing more. This is why you should alwaysexitordie()after setting a Location header, unless you know exactly what you are getting yourself into by not doing it.As for what you’re trying to do, it’s a bad idea. Deliberately having a request take 15 seconds is just asking for a DOS attack.