I have a bug which makes my website freeze in PHP. It occurs on an input page, where the user fills some form, then the data is updated on the database, and then the user gets header redirected to another page.
What happens is that the whole website “branch” (subfolder, e.g. www.example.com/my_site, but not www.example.com/another_site) freezes, but no other Chrome accessed web location. After a while, I can navigate on that site again, I presume after the Chrome operation timed out.
However, this only seems to happen on Chrome, and on my Mac. I tested another Safari on that Mac, Chrome on a Windows, and both worked well. I must admit this testing wasn’t extensive, but I only have 1 Mac to test with. This little venn-like testing crossed browser and machine, which I think are the key factors.
Here is the code of the bugging page. If I comment out the header redirection, I get no dreezing. If I comment out the page update code, I get no freezing. I don’t see what causes the freeze here, really. Machine? OS? Header redirection? $_POST operation? try/catch handling? Combination? I have no idea.
EDIT: I now see a correlation between the amount of data passed through $_POST from the form to the page. If the data is relatively small, everything works correctly. However, when I get bigger data (i.e. HTML markup through a WYSIWYG editor field), the freeze occurs. How is Chrome affected by that? Maybe the redirect occurs before it can process it all? Even with ginormous amounts of data, it still works fine on Mac/Safari and Windows/Chrome.
<?php
require_once("script/initialize.php");
try
{
if (isset($_POST["submit"]))
{
$page = page::from_post();
try
{
$page->validate();
$page->require_edit();
$page->update_by_id();
$page->set_tags_from_post();
$page->set_categories_from_post();
$page->set_workgroups_from_post();
//header("Location: page_view.php?id=".$page->id);
}
catch (InputException $inex)
{
$smarty->assign("error", $inex->getMessage());
}
}
else
{
$page = page::from_id(intval($_GET["id"]));
$page->require_edit();
}
$smarty->assign("ressource", $page);
$smarty->display_self();
}
catch (Exception $ex)
{
$smarty->display_exception($ex);
}
?>
I had the exact same issue on a Mac in Firefox. When uploading small files <100kB it worked fine 90% of the time, but with larger files (e.g. photos from a digital camera) Firefox seemed to be waiting for a response from the server. When this was happening I couldn’t connect to the same domain from another Firefox window, but opening any other page worked fine.
The server was working fine – I checked that on a different computer while the Mac didn’t have connection.
3-5 minutes later it “woke up” and was working fine.
Then I found out that there wasn’t an
exit();after the redirect header in the upload script. I inserted it, and now I haven’t seen any of these issues.Just want to confirm that a missing
exit();after aheader("location: [URL]");can cause browser(s) on a Mac to hang.