Track Database Job Progress with AJAX and PHP

Keep database progress updates small and predictable

Store the job status separately from the page. The polling endpoint should return only the fields needed by the progress component.

const response = await fetch(`job-status.php?id=${encodeURIComponent(jobId)}`, {
  cache: 'no-store'
});
const status = await response.json();

progress.value = status.percent;
statusText.textContent = status.message;

Current approach first; the original XMLHttpRequest/AJAX examples below are retained and cleaned up for continued learning and legacy maintenance.

In applications where the main script takes time to execute the full code, we can have some break ups or some landmark points at some intervals. Once the execution completes these landmarks then it will update a table with status indicating the completion of the part. Our progress monitoring script will interact with this table to take the feedback and display the progress bar accordingly.

We have already seen how the progress bar is displayed. We will extend the same technique to show a growing status bar as per the script execution.

DEMO of Progress Bar Process

Here is the block diagram of the process.

progress-bar2-demo.php

There is not much difference in basic progress bar script and this. Through a timer it reads data from progress-bar2.php and manage the value attribute of progress tag.

progress-bar2.php

This page reads the data from the status table and returns the same to progress-bar2-demo.php through Ajax to display the progress bar image.

progress-bar2-1.php

This script first deletes all the records of the status table and then updates it with different stage values. To create some delays in script execution sleep() function is used. At the end of each stage the status table is updated.

Download the zip file for all these three scripts
Ajax Json XML


Subscribe to our YouTube Channel here



plus2net.com







Raza

15-09-2014

Here in your example, no popup opens and ajax responses ok but in downloaded file, it opens a popup which i dont want
smo

17-09-2014

The script can be executed without popup like this
require "progress-bar2-1.php";

Download a copy now. PDO support is added.




PHP video Tutorials
✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer