in reply to Re: Other Script Processes
in thread Other Script Processes

Yes, I need to know how many different people are on our website. We just launched this program and already have over 10k members, so the problem is that there are people on this website all the time.

Therefore If I make a change to the core files, and someone is loading the file they get an error. I want to minimize that so it would be very helpful if I can figure out how many people are on the main scripts which there are two of them the index.cgi script and the members.cgi script, both of them load the same core files. So if I can figure out how many different people are on them I can try to upload the files when there are none, or just a few. I can pass a message to all visitors that says "we are updating a core file if you get an error please wait 2 minutes and try again. sorry for the inconvenience... blah blah... whatever..." Anyhow, I try to keep each file a small file, like 2k lines or less, then I just pull each file in from the main core file. That way when I upload it uploads really fast, so it does not cause much interuption.

I appreciate everything.
thx,
Richard

Replies are listed 'Best First'.
Re^3: Other Script Processes
by ikegami (Patriarch) on Nov 17, 2007 at 02:38 UTC

    If I'm not mistaken, rename is atomic on unix, so instead of copying your new file over the old one, move it over.

    For example, upload the new index.cgi as index.cgi.new, then issue mv index.cgi.new index.cgi.

      Ok, so If I am updating the core file, vars.conf which has all that magic in it, then name it vars2.conf then just use unix to overwrite it and it should not interfere with users loading pages?

      Is that correct?
      thx,
      Richard

        I believe so. Even if some processes have the file is open (say the perl parser), it's not a problem since the actual file on disk isn't changed. The perl accessing the old version of the file will continue to access the old version (which will get deleted once all file handles to it are closed). New perl instances will see the new file and open and parse that one.

        I'm assuming you're only reading from this file.

        If the core file is "vars.conf", you want to copy that to some other name (like "new-vars.conf"), alter the contents of that copy as needed, and when you are sure it is ready for use, just:
        mv new-vars.conf vars.conf
        (as a shell command) or just rename "new-vars.conf", "vars.conf" (as a step in a perl script -- same thing). That way, no one will ever get a partial (or partially edited) version of the file. Assuming the file is read only once per client process, there won't be any inconsistencies from the client's perspective.