The title might be a little odd but I can't really describe it any other way. I have the following code:
error_reporting (E_ALL ^ E_NOTICE);
require_once("required/config.php");
$mysqli = new mysqli($db_server, $db_username, $db_password, $db_database);
for ($i = 1; $i < 1001; $i++) {
if ($insertItem = $mysqli->prepare("INSERT INTO testtable (dummyfield) VALUES (?)")) {
$insertItem->bind_param('s', $value);
$value = "Just some data #$i";
$insertItem->execute();
$gebruikersId = $mysqli->insert_id;
$insertItem->close();
echo $value . "<br />";
}
}
$mysqli->close();
When I run this code it takes about 20 - 30 seconds. That's fine. I open a second window and I can browse to and from every other page from the website. No problem here.
However, when I add session_start(); right below error_reporting other pages won't load until the for-loop / importing has finished.
Any ideas? I've tried Google but couldn't find any relevant results.
As long as one script “uses” the session, the session file is locked – and other scripts wanting to use the same session have to wait until the lock is released.
Avoid this by calling session_write_close()
as early as possible in your long-running script.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With