3

I am struggling with something.

I have an PHP page that does an ajax call to another page using jQuery $.ajax. It sends the request async to the processing page which then returns a response.

This works fine now but we are making some changes to the backend and the processing (SQL stored procedure) that runs is now taking a lot longer like well over 5 minutes. The wait is is fine because we are dealing with close to 200MM records in SQL.

The thing is I need to be able to send the request to the processing page and not have to wait for a response. The processing page fires off the stored procedure in PHP like this:

            $query = $dbh2->prepare('exec sp_name :countID');
            $query->bindParam('countID', $countID);
            $query->execute();

Now again that stored procedure takes awhile to run and we do not need the results of that to be presented back to the user. There is though some additional PHP code that needs to run after the stored procedure but again nothing needs to be send back to the browser.

I am trying to figure out a way that I can make a call to the processing page and it runs the stored procedure and the other code but the user's browser does not need to wait for the response. Right now if the try to click off the page too soon it basically locks up the browser for awhile and does not finish the processing.

Any insight into this would be great.

Thanks in advance for any help.

twasbrillig
  • 17,084
  • 9
  • 43
  • 67
Sequenzia
  • 2,333
  • 9
  • 40
  • 59
  • 1
    maybe use http://php.net/manual/en/function.exec.php and then execute a file on the server with it and return 'ok' to the browser. – nathan hayfield Apr 03 '13 at 23:41
  • i think what you want is Asynchronous PHP calls?[http://stackoverflow.com/questions/124462/asynchronous-php-calls] – Borik Apr 03 '13 at 23:49

2 Answers2

2

Sequenzia, if I understand correctly, then I've been here and found a way through this quagmire after a lot of research.

I provided an answer to a similar question a few months ago. Unfortunately, the OP nor anyone else has ever accepted/commented/upvoted/downvoted - nada.

And here are some useful references :

Running a background script (unix command)

How to compose PHP $shortopts and $longopts

This is the way to interpret parameters passed to a PHP script when run from the command-line, or from another PHP script with shell-exec()

Community
  • 1
  • 1
Beetroot-Beetroot
  • 18,022
  • 3
  • 37
  • 44
0

You might look at setting the timeout option for the $.ajax() method. By setting a timeout of maybe half a second or whatever, the ajax will just timeout and go into the error handler (if any).

Mike Brant
  • 70,514
  • 10
  • 99
  • 103
  • 1
    Thanks for the help. I tried setting a timeout on the $.ajax() request and it does timeout and fires off the error handler but the browser still locks up until the process is complete. Any other ideas about this? – Sequenzia Apr 04 '13 at 01:05