A
A
Alex Ponomarev2022-04-17 17:22:59
PHP
Alex Ponomarev, 2022-04-17 17:22:59

How to run a loop in the background and display its result on the site?

Before me is a task beyond my strength. If the loop is running for a while, when it runs the site will load. After the cycle is completed, I need its data to be placed on the site, and thanks to this, the data changes on the site. How to make it so that when the cycle is executed, the site is loaded in the usual mode and gives access to the site information. And when the site is loaded, then the data from the cycle will come and some part of the site will change. Is it real at all?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
alekssamos, 2022-04-17
@rusindex

In a normal way, queues were made for this.
Queues on Gearman and PHP
Cons: on free hostings it is not feasible or inconvenient.
Plus: it can withstand even a heavy load, the server will not fall.
It is not normal to run the script through curl or the console in the background
without waiting for completion,
it will write the result to a file or to the database
and periodically check whether the result has appeared or not.
Minus: under load, the server will fall.

I
Ilya, 2022-04-17
@New_Horizons

Take out the "loop" in a separate request, receive data via ajax

I
irishmann, 2022-04-18
@irishmann

Break the page into blocks. The main page is static, infa which does not change. The rest is loaded via AJAX.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question