Reputation: 41
So, my situation is this. I need to import large mysql dumps into a Database using a PHP script and AJAX calls.
I have written a recursive AJAX function, which is communicating with the PHP script and sending back-an-forth all the necessary data(like position of pointer in the .sql file) to cut the next chunk from the .sql file and run it until the script reaches the end of the file.
The problem I am encountering is, that some mysql dumps have let's say variables defined in the beginning of the file and are using them later in the file. If these 2 segments of code are not in the same chunk, I am getting a SQL error, because the variables used are not defined.
So generally, I wonder, if there's a way to store the connection/state of the session, to restore it later and be able to use session variables.
Thank you!
Upvotes: 2
Views: 242
Reputation: 522155
Only if you make your PHP script persistent. In a general HTTP setup, each call to PHP creates a new PHP instance which is torn down when the request ends. That necessarily ends that MySQL session and any temporary data you have created during that request.
You can write a persistent worker in PHP which runs indefinitely and answers request from some sort of message bus, say Gearman, ØMQ or Crossbar. So a request would go something like:
browser ⇄ web server ⇄ ephemeral PHP instance ⇄ Gearman ⇄ persistent PHP worker
In that persistent worker, you can persist anything you want. That obviously requires a bit of a special server setup and won't be possible on generic shared hosting and such.
Upvotes: 1