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

  • Home
  • SEARCH
  • 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 6838507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:36:20+00:00 2026-05-26T23:36:20+00:00

What I’m after is a PHP-script which will provide a local copy of a

  • 0

What I’m after is a PHP-script which will provide a local copy of a javascript file stored on a different domain, e.g. JS-files used for tracking purposes, such as Google Analytics or, in my case, WordPress Stats.

The intention is to add it as follows in my own :

 mysite.com/somepath/wpstats.js.php?w=201145

(where “w=year-week_number” is used in the same way as by wordpress.com. Their cache expiry for there original stats JS-file is one year – hence the JS-file will never be changed more often than once a week)

In my wpstats.js.php I want to download the correct file from wordpress.com when w=xx changes, otherwise I want to return it from a locally kept copy.

I can implement it with one internal variable called “w_current”, so that when a new visitor enters the site the second week w != w_current and it will trigger a new fetch. The problem is: how do I prevent race-conditions/parallelism problems that might occur when two website visitors simultaneously loads the website the first time the second week [1]?

[1] both apache-processes evaluate the w != w_current and starts two downloads of the (potentially) new version of the wpstats.js-file and both try to write it to the local copy (e.g. own_wpstats.js) which wpstats.js.php (in the normal case where a local copy already exists) will include:

if ($_GET["w"] == w_current) require("own_wpstats.js");

The main reason for doing this (performance possibly being another) is due to the fact that WordPress.com Stats injects (via DOM) an additional JS-tracking file from a third party, quantserve.com. In my locally kept “WP JS file” I will make sure this quantserve.com thing is excluded, but this is a separate programming challenge than the question I try to ask here. A search for “quantserve.com tracking cookie” gives many discomfortable results.

  • 1 1 Answer
  • 0 Views
  • 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-26T23:36:21+00:00Added an answer on May 26, 2026 at 11:36 pm

    I wouldn’t worry TOO much about such a race condition. “Worst case” is you download the file twice.

    But IF you are going to be doing ANY tracking of these files in a DB, then preventing the double download would be simple. Immediately before you start the download, check DB if file needs a refresh, log the refresh to the DB, and THEN do the download. Give the file a unique primary-key (site_url + file_name) and the second check before update will fail.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a bunch of posts stored in text files formatted in yaml/textile (from
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,

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.