S
S
Sergey Balashov2015-12-10 09:55:36
PHP
Sergey Balashov, 2015-12-10 09:55:36

Using AJAX in a lengthy PHP script. How to implement?

The script takes a very long time to execute using a third party API. I would like to add interactivity. What is the best way to do this?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
T
Tonako, 2015-12-10
@Tonako

Split the script into several parts and files

S
Sergey Balashov, 2015-12-10
@BSB

Doesn't fit in understanding yet.
Here, for example, is line-by-line processing of a file.
Can you give an example of how to split?

I
Immortal_pony, 2015-12-10
@Immortal_pony

The acronym "AJAX" is indirectly related to your desires.
The required functionality can be achieved using multithreading.
Details about multithreading in PHP and how to use it are written in the answer - stackoverflow.com/questions/209774/does-php-have-t...

K
Kirill Arutyunov, 2015-12-10
@arutyunov

Need to load a page for the user and show that something is happening and the process is going on?
Then make page 1 that will show the interface to the user, and from this page send a request to page 2 that will communicate with the external API. Before starting the request on page 1, put some gif "Loading in progress ...", and after a successful ajax request, remove the gif and return the results of the request.
The long loading of page 2 will not interfere with quickly showing the interface of page 1 to the user.
If you really need to quickly execute the script on page 2, then you already need to think about multithreading, optimizing the work of the script itself, setting up the server, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question