Runtime line updates with php script

I am writing a small application that does the following:

  • Allows user to download excel file
  • Reads data from each column of an excel file and creates an image based on the data

Right now I upload files and call a script that goes through the file, creates images, creates a page (or db record) with each pic name, and then displays them on the screen. I would prefer that he notify of the use of this progress. I would like the PHP script to force the images to be called via ajax (I know how to do this), but in order to essentially return the value JSON, HTML, plain text, it doesn't really matter.

Is this doable? I'm using jQuery, so maybe there is a function in AJAX calls that I don't know about?

+4
source share
5 answers

Yes, it is doable. This is not a jQuery function, since it requires server-side integration. Here is an approximate sketch of how to implement it:

  • There is a database table (or other equivalent types of storage) in which key-value pairs are stored. This is easier if both keys and values ​​are strings.
  • When the task is initiated, create a unique row that is the key and the value 0 that you store in the database table. The user is also redirected to a URL containing this unique string. For instance. "/ MySite / ERxQl3ew".
  • Using jQuery, the user client should poll the URL "/ getkeyvalue / ERxQl3ew". This URL should check the database and get the job status of, say, “45.3” to indicate that the work is 45.3% complete. This is easier if the page is a JSON string.
  • The server should update the row with the ERxQl3ew key when the status or progress of this task changes.
  • When the task is completed, the server can set the string value to "final" to indicate that the task is complete. When the javascript client sees this value, it must redirect the user to the destination destination page or otherwise indicate to the user that the task has been completed.

Perhaps this sounds more complicated than it really is. This is pretty trivial to implement.

+3
source

I do not think so. If you want progress to be checked, you will need to check through jquery, I don't know every 2 seconds. the problem is that you will have to run the php script asynchronously and report the internal progress you are requesting through javascript. It is impossible for you to download any material, and without doing anything, your php scripts will tell you something

0
source

I recommend the following:

  • you need to make some progress indicator, for example a file in which you write how far the formatting process has gone sofar
  • you also need php that reads this file and tells which precentage it reads from it.
  • you need to call this php with ajax periodically until it reads 100%

Also remember to use some token to control concurrent use.

0
source

jQuery has a progress bar, and there are also several PHP scripts that return a "progress" that displays the status of the script. Here is a blog that I came across a while ago. An alternative PHP caching method (APC), as well as the UploadProgress method. Both are PECL packages. hope this helps

howto-php-and-jquery-upload-progress-bar

0
source

It is doable.

There are several ways to actually do this, but one very simple way is to have a database table that tracks imports. When the row is processed, refresh the database table, and then call JavaScript through a PHP script in a few seconds via Ajax, and it can return full rows and processed rows or percentage, etc.

The scheme can be absolutely simple:

Import ID | Total Rows | Processed Rows --------------------------------------- 100 | 12125 | 1246 101 | 6212 | 1302 
0
source

Source: https://habr.com/ru/post/1338444/


All Articles