Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 411549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:59:52+00:00 2026-05-12T17:59:52+00:00

EDIT I just realized that I must have had a massive brain fart while

  • 0

EDIT I just realized that I must have had a massive brain fart while writing the abbreviated code sample. See, I’m using smarty. Thus, I’m actually already using Kips’s solution, because smarty displays after the session is saved

I’ve been working on implementing a resource manager (for condensing, compressing and minifying CSS & JS) for a PHP site I’m working on and have run into an awfully strange problem. So when a user navigates to index.php, files are added to a resource manager object, which combines them into a single file and are included in the page via either <script src="resource.php?id=123&ext=.js"> or <link href="resource.php?id=123&ext=.css" />

What it basically boils down to is that a file path is stored in a session on the accessed page and read from the session on the resource page. In FF, this works perfectly fine. In IE and Chrome, it does not.

Here’s a much-abbreviated code sample:

index.php

<?php
session_start();
//Do a ton of stuff
//Including adding several files to the resource object
//Add the resource links to the head
$smarty->append('headSection','<link href="resource.php?id=<?=$resourceID?>&type=.js" />');
</head>
//Save the resource file which:
// - Outputs the file
// - Saves a reference to it in session
$_SESSION[$resourceID] = $file;
//Let Smarty display
$smarty->display($templateFile);
?>

resource.php

<?php
readfile($_SESSION[$_GET['id']] . $_GET['type']);
?>

What it seems like to me is that FF waits for an entire page response before making any new requests to the resources required by the page, while IE and Chrome function by starting a new request the second it is encountered. Due to this, this error basically boils down to a race condition.

Can anyone confirm that this is indeed the way it works? And if so – how would I work around it?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T17:59:52+00:00Added an answer on May 12, 2026 at 5:59 pm

    Edit: After the update to your question, then I am not surprised that you are getting a race condition. I don’t know why it is working in Firefox, but IE and Chrome are certainly not doing anything illegal by requesting the resources early. One way you could resolve this is with output buffering. At the top of your index.php file, you can add:

    ob_start('ob_gzhandler');
    

    This kills two birds with one stone, by: a) making sure that output is buffered, so the browser doesn’t see the file until the whole page has been generated; and b) saving you and your users bandwidth by using gzip compression.


    Previous answer: That doesn’t seem to make sense. Cookies can only be set in the header, which happens before any page content is loaded. So the browser requests index.php, and the PHPSESSID cookie is set in the header. Then the page content is delivered.

    I don’t have access to a machine with PHP at the moment, but the following might help to test your theory. test1.php sets a session variable, but then takes 30 seconds to completely finish loading. Meanwhile, test2.php (a CSS file) will try to use that session variable as the text color. The text will show up red if the session could be read from test2, or black (default color) otherwise.

    test1.php

    <?php
    session_start();
    $_SESSION['mycolor'] = 'red';
    ?>
    <html>
    <head>
    <link rel="stylesheet" href="test2.php" type="text/css" />
    </head>
    <body>
    Starting test...<br/>
    <?php
    for($i = 0; $i < 6; $i++) //loop will take 30 seconds to complete
    {
      echo "$i<br/>\n";
      sleep(5);
    }
    ?>
    Done!
    </body>
    </html>
    

    test2.php

    <?php
    session_start();
    ?>
    body { color: <?php echo $_SESSION['mycolor']; ?>; }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have just realized that the code I was working on for 3d
EDIT 2: I have just realised that my HTML is only displaying the artist
EDIT: I just realized that this question may be better suited to ServerFault. Instead
-- EDIT: I just realized that the right answer to this is maybe a
Edit: just to be clearer on what I am looking to do. I have
EDIT I've just started skimming Codd's famous 1970 paper that started it all, that
I have to edit my question just to make it clear. What I need
Edit: Turns out I just had some values -switched-. I'm working with OpenGL and
Edit For simplicity: I just want to make the most basic possible cursor that
I just realized that DBUnit doesn't create tables by itself (see How do I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.