A
A
Art4es2017-10-02 12:21:01
PHP
Art4es, 2017-10-02 12:21:01

How to stop php script execution using js?

I load the page, and after loading I pull up the data from the database using xmlhttprequest. It happens that you have to wait more than a minute for a response from the server, and you can’t leave this page by clicking on the navigation element. Is there any way to stop php script execution with js?
The request is asynchronous. All events on elements work.
.abort() kills the request, but until the server responds, you can't leave the page.
I believe that it is necessary to somehow break the connection with the server in order to stop the execution of the script, but I don’t know how to do this.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vladimir Skibin, 2017-10-02
@Art4es

You most likely have a classic problem with sessions. The AJAX script, although asynchronous, occupies a handle to work with the session file. And until he finishes it (the end of the script, or through a function), the file will not be released and the user will not be able to make any other request. There are several solutions:
1. Transfer work with sessions to the database/memcached/redis
2. Close the session after reading it and write changes at the end of the script (if any).

E
Evgeny Kalibrov, 2017-10-02
@rework

at the same time, it is impossible to leave this page by clicking on the navigation element.

Why can't you leave the page then?

T
ThunderCat, 2017-10-02
@ThunderCat

... I pull up the data from a DB by means of xmlhttprequest. It happens that you have to wait more than a minute for a response from the server, ..
If I were you, in this situation, I would first of all deal with the work of the database, which gives data for more than a minute. This is number one.
The second - if there is really a lot of data there - break it into pieces and make several requests, after loading 1 piece, start the second one, and so on, so it will be possible to interrupt work on the client, not on the server, which is much easier as you understand.
Option 3, with loaded calculations - run a script on the server in a separate thread, write the result to some storage (you can directly back to the database, but I think radish is a more suitable option for this), request the result by long polling or by timer every n seconds .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question