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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:01:20+00:00 2026-05-22T12:01:20+00:00

I have a PHP script something like: $i=0; for(;$i<500;++i) { //Do some operation with

  • 0

I have a PHP script something like:

$i=0;
for(;$i<500;++i) {
   //Do some operation with files numbered 0 to 500;
}

The thing is, the script works and displays the end results, but the operation takes a while and watching a blank screen can be frustrating. I was thinking if there is some way I can continuously update the page at the client’s end, detailing which file is currently being worked upon. That is, can I display and continuously update what is the current value of $i?

The Solution

Thanks everyone! The output buffering is working as suggested. However, David has offered valuable insight and am considering that approach as well.

  • 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-22T12:01:21+00:00Added an answer on May 22, 2026 at 12:01 pm

    You can buffer and control the output from the PHP script.

    However, you may want to consider the scalability of this design. In general, heavy processes shouldn’t be done online. Your particular case may be an edge in that the wait is acceptable, but consider something like this as an alternative for an improved user experience:

    1. The user kicks off a process. This can be as simple as setting a flag on a record in the database or inserting some “to be processed” records into the data.
    2. The user is immediately directed to a page indicating that the process has been queued.
    3. An offline process (either kicked off by the PHP script on the server or scheduled to run regularly) checks the data and does the heavy processing.
    4. In the meantime, the user can refresh the page (manually, by navigating elsewhere and coming back to check, or even use an AJAX polling mechanism to update the page) to check the status of the processing. In this case, it sounds like you’d have several hundred records in a database table queued for processing. As each one finishes, it can be flagged as done. The page can just check how many are left, which one is current, etc. from the data.
    5. When the processing is completed, the page shows the result.

    In general this is a better user experience because it doesn’t force the user to wait. The user can navigate around the site and check back on progress as desired. Additionally, this approach scales better. If your heavy processing is done directly on the page, what happens when you have many users or the data processing load increases? Will the page start to time out? Will users have to wait longer? By making the process happen outside of the scope of the website you can offload it to better hardware if needed, ensure that records are processed in serial/parallel as business rules demand (avoid race conditions), save processing for off-peak hours, etc.

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

Sidebar

Related Questions

end goal is to have the bash run something like php script.php argument1 argument2
I am using PHP and I need to script something like below: I have
I have a php script which can take some GET params. I would like
I have a php script which accesses a MSSQL2005 database, reads some data from
I have some troubles with encoding and mailing. I send post-request to php-script, when
I have a php mail script that works well except for one minor fact.
I'm creating a PHP script that imports some data from text files into a
I have a php script which generates an image, and is used (mainly) like
I have a PHP script that simply takes some data, separates it into tab
I have a php script that generates a binary file (is some kind of

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.