Jump to content

Executing Script Twice


bsmither

Recommended Posts

I have noticed through diagnostic code I added to CubeCart files, that the whole process (waking up, fetching data, rendering pages, shutting down) happens twice.

This could be the fault of the web server I run -- I will also look at another installation I have running with Apache.

If anyone wants to check their installation, try this:

In a new file at the root folder of your store, ini-custom.inc.php

<?php

	$dbg_fp = fopen(CC_ROOT_DIR . CC_DS . "dbg_log.txt", "a+");

	fwrite($dbg_fp, strftime('%X').date('T')."--- INI-Custom File"."rn");

	fclose($dbg_fp);

?>

Then visit your site. Then browse to www.store.com/dbg_log.txt

How many lines are in your log (having the same time)?

Link to comment
Share on other sites

I installed your file, then logged out, logged back in, and went to the main Admin Products list. This is what is in my dbg_log.txt file:

22:33:45UTC--- INI-Custom File

22:33:54UTC--- INI-Custom File

22:33:56UTC--- INI-Custom File

22:33:57UTC--- INI-Custom File

22:34:01UTC--- INI-Custom File

22:34:01UTC--- INI-Custom File

22:34:01UTC--- INI-Custom File

22:34:01UTC--- INI-Custom File

22:34:13UTC--- INI-Custom File

22:34:31UTC--- INI-Custom File

This is an Apache server.

Link to comment
Share on other sites

So you had three events (and the three have no discernible breaks in the timeline):

Log out -- :45 - :57 :: one wake-up to process the logout and three restarts to get a login page (although nine seconds to get from the first to the second is crazy).

Log In -- :01 - :01 :: one wake-up to process the log on and three restarts to get the Dashboard

Products Listing -- :13 - :31 :: one wake-up to process the request and one restart (eight seconds later).

Rename the file to ini-custom.inc.old so that it doesn't continue to build onto the text file.

I'll have more requests later.

Link to comment
Share on other sites

Research shows this is a problem that many developers have run into. The common culprit to blame is:

<img src="" />

That is, an img tag with no address as to where to fetch the image from. The reasoning is that the browser substitutes the last known good address for the missing location - which is another call to the same page and the PHP script runs again. But this was a few years back and I'm sure modern browsers don't do that anymore. (But I don't experiment with all that many different browsers.)

My experiments have revealed that CubeCart running twice is: once from a legitimate request from the browser, and a second when the server receives an XMLHttpRequest. Oddly, in light of what I just mentioned above, it seems (that is to say, a wild guess) the XMLHttpRequest has no address and so the browser may be using the last known good address as a substitute.

XMLHttpRequest is the proper name of the browser function that accomplishes AJAX calls.

So, the question is, where in CubeCart's javascript files is an AJAX call being made with no URL specified?

(As an aside, I was 100% sure it was a problem with Cubecart's PHP coding as I had never before seen the second HTTP GET request headers, even though I'm pretty good at taking notice of such things.)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...