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 6196031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:34:21+00:00 2026-05-24T03:34:21+00:00

Ok here is my problem. I have a file which outputs an XML based

  • 0

Ok here is my problem.

  1. I have a file which outputs an XML based on an input X
  2. I have another file which calls the above(1) file with 10000 (i mean many) times with different numbers for X

When an user clicks “Go” It should go through all those 10000 Xs and simultaneously show him a progress of how many are done. (hmm may be updated once every 10sec).

How do i do it? I need ideas. I know how to AJAX and stuff, but whats the structure my program should take?

EDIT

So according to the answer given below i did store my output in a session variable. It then outputs the answer. What is happening is:

When i execute a loong script. It gets executed say within 1min. But in the mean time if i open (in a new window) just the file which outputs my SESSION variable, then it doesnt output will the first script has run. Which is completely opposite to what i want. Whats the problem here? Is it my syste/server which doesnt handle multiple requests or what?

EDIT 2

I use the files approach:
To read what i want

> <?php include_once '../includeTop.php'; echo
> util::readFromLog("../../Files/progressData.tmp"); ?>

and in another script

$processed ++;
util::writeToLog($dir.'/progressData.tmp', "Files processed: $processed");

where the functions are:

   public static function writeToLog($file,$data) {
        $f = fopen($file,"w");
        fwrite($f, $data);
        fclose($f);
    }
    public static function readFromLog($file) {
        return file_get_contents($file);
    }

But still the same problem persist :(. I can manually see the file gettin updated like 1, 2, 3 etc. But when i run my script to do from php it just waits till my original script is output.

EDIT 3

Ok i finally found the solution. Instead of seeking the output from the php file i directly goto the log now and seek it.

  • 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-24T03:34:22+00:00Added an answer on May 24, 2026 at 3:34 am

    Edit: I was wrong about $_SESSION. It doesn’t update asynchronously, i.e. the values you store in it are not accessible until the script has finished. Whoops.

    So the progress needs to be stored in something that does update asynchronously: Memory (like pyroscope suggests, and which is still the best solution), a file, or the database.

    In other words, instead of using $_SESSION to store the value, it should be stored by memcached, in a file or in the database.

    I.e. using the database

    $progress = 0;
    mysql_query("INSERT INTO `progress` (`id`, `progress`) VALUES ($uid, $progress)");
    # loop starts
        # processing...
        $progress += $some_increment;
        mysql_query("UPDATE `progress` SET `progress`=$progress WHERE `id`=$uid");
    # loop ends
    

    Or using a file

    $progress = 0;
    file_put_contents("/path/to/progress_files/$uid", $progress);
    # loop starts
        # processing...
        $progress += $some_increment;
        file_put_contents("/path/to/progress_files/$uid", $progress);
    # loop ends
    

    And then read the file/select from the database, when requesting progress via ajax. But it’s not a pretty solution compared to memcached.

    Also, remember to remove the file/database row once it’s all done.


    You could put the progress in a $_SESSION variable (you’ll need a unique name for it), and update it while the process runs. Meanwhile your ajax request simply gets that variable at a specific interval

    function heavy_process($input, $uid) {
        $_SESSION[$uid] = 0;
        # loop begins
            # processing...
            $_SESSION[$uid] += $some_increment;
        # loop ends
    }
    

    Then have a url that simply spits out the $_SESSION[$uid] value when it’s requested via ajax. Then use the returned value to update the progress bar. Use something like sha1(microtime()) to create the $uid

    Edit: pyroscope’s solution is technically better, but if you don’t have a server with memcached or the ability to run background processes, you can use $_SESSION instead

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

Sidebar

Related Questions

I have a shell script that calls a java jar file and runs an
OK, so here's the background: We have a third-party piece of software that does
I posted a question yesterday here: Finding and adding to a .kml file using
I've got a class that represents an XML file to be processed. I've created
I have problems regarding the output of the XMLReader , which should be able
I'm getting an error here that says I haven't defined a method, but it
This is beyond both making sense and my control. That being said here is
I would like to remove/delete a migration file. How would I go about doing
Let say I have the following desire, to simplify the IConvertible's to allow me
I have found this example on StackOverflow: var people = new List<Person> { new

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.