使用php在服务器上显示进度的最佳方法

What are best ways to display progress on server work?

  1. xhr processing request
  2. iframe method ( i dont prefer this method )
  3. server sent events
  4. polling with some flash messages on $_SESSION variable in main php script

which is most clean and most used way?

use case is for example when we upload zip files, i want to track progress on unpacking, copying files etc

Your question is a bit vague - there is no "best" way, each one has advantages and disadvantages. Try to explain what is important to you.

For example, the most clean, scalable and performant way would probably be to push an update on progress to the client using WebSockets. However, this may require some special implementation on the server and client side and may be a bit complex.

On the other hand, if you want simplicity and ease of implementation and are willing to sacrifice performance and scalability, going with a $_SESSION + Ajax polling solution could be better - however you should be careful as some session storage backends lock the session which means you cannot have one PHP request updating it while another is attempting to read from it. You can instead use DB / memcache / file storage (depending on your scale needs and server setup) to store this information.