How are AJAX progress indicators implemented for modern PHP web applications?

I have seen many web applications that implement progress indicators, however my question is about non-downloadable diversity.

Many PHP web applications (phpBB, Joomla, etc.) implement a smart installer that not only helps you install the software, but also informs you of what it is doing now. For example, if the installer created SQL tables or wrote configuration files, he reported this without asking for a click. (Basically, the setting is β€œsedentary and relaxed.”)

Another good example is with Joomla Akeeba Backup (formerly Joomla Pack). When you back up your Joomla installation, it makes a complete archive of the installation directory. This, however, is time consuming and therefore requires updates of progress. However, the server itself has a PHP script execution time limit, and therefore it seems that either

  • A backup script may get around it.
  • Some temporary data is stored so that the archive is added (if adding the archive is possible).
  • Client scripts often invoke the PHP server so often to perform actions.

My general assumption (not specific to Akeeba) is C # 3, i.e.:

  Web page JS -> POST foo / installer.php? Doaction = 1 SESSID = foo2
 Server -> ERRCODE SUCCESS
 Web page JS -> POST foo / installer.php? Doaction = 2 SESSID = foo2
 Server -> ERRCODE SUCCESS
 Web page JS -> POST foo / installer.php? Doaction = 3 SESSID = foo2
 Server -> ERRCODE SUCCESS
 Web page JS -> POST foo / installer.php? Doaction = 4 SESSID = foo2
 Server -> ERRCODE FAIL Reason: Configuration.php not writable!
 Web page JS -> Show error to user

I am 99% sure that this is not the case, as this will create a very nasty user dependency to enable Javascript.

I think my question comes down to the following:

  • How long do PHP scripts work (on web servers, of course) and can "stay alive" for the maximum PHP runtime? If they do not β€œcheat,” how can they share the task at hand? (I notice that Akeeba Backup confirms the maximum PHP runtime, but I don't want to dig too deep to find such code.)
  • How is progress displayed through AJAX + PHP? I read that people use the file to indicate progress, but for me it seems "dirty" and a little annoying to work with I / O, especially for live servers with more than 10,000 visitors working with the above script.

The environment for this script is where safe_mode is turned on and the limit is usually 30 seconds. (In principle, the restrictive, free host is $ 0.) This script is aimed at all audiences (will be made public), so I have no authority over which host it will be on. (And this suggests that I will not blame the end user for having a bad host.)

I don't necessarily need code examples (although they are very much appreciated!), I just need to know the logical flow for its implementation.

+4
source share
1 answer

Typically, such a thing is stored in the $ _SESSION variable. Regarding the execution timeout, what I usually do is have a JavaScript timeout that sets innerHTML to the update status div in the PHP script every x seconds. When this script is executed, it does not β€œwait” or anything like that. It just captures the current status from the session (which is updated through the script (s) that / actually performs the installation), and then outputs this to any suitable method that I think is appropriate (status bar, etc.).

I would not recommend direct I / O for status updates. You are right that it is dirty and inefficient. I would say that $ _SESSION is definitely the way here.

+1
source

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


All Articles