Jump to content

MySQL query in background


Azu

Recommended Posts

Sometimes in PHP I need to run a query, but the query will take a long time, and my PHP doesn't need any feedback from the query.

How do I make it so that my PHP just tells MySQL to execute the query and then just goes on executing the rest of the script instead of waiting for the query to complete before moving on?

Link to comment
Share on other sites

It isn't supposed to run every certain amount of time though, and it has variables in it based on things in PHP.

Can't this be done without threading? I just want it to send the query to MySQL, and then that's it, just forget about it and move on.

Link to comment
Share on other sites

In order for php to run anything in the background it would need to thread a new process for it to be done in. While threading may be available in some cases within php on the command line, it most definately is not recommended or compiled into the php module within apache.

Link to comment
Share on other sites

In order for php to run anything in the background it would need to thread a new process for it to be done in. While threading may be available in some cases within php on the command line, it most definately is not recommended or compiled into the php module within apache.

Oh okay.

I think I worded it wrong then sorry.

 

You know how usually when you use mysql_query to run a query, it sends the query to MySQL, and then it waits, listening for a response? I want it to just send the query to MySQL, and that's all. I don't want it to do anything else. I don't want it to sit there waiting for a reply. I don't want it to continue doing anything in the background. I want it just move on and forget about it, instead of listening for feedback, since no feedback is needed from this whatsoever. So it shouldn't need threading since it is just sending the query and then forgetting about it and moving on.

 

I think that you confused this with thinking that I wanted it to act normal but run the rest of the script while it's doing what it normally does (sitting there waiting for a response from MySQL).

Link to comment
Share on other sites

Thanks, that does work a bit. The problem is that the only reason I want to do this is to remove overhead, and doing it that way would require creating a new file, writing the data to it, saving it, then starting up a new PHP process, having it read and parse the file, and then tearing down that PHP process and deleting the file. This is overhead.  :/

 

It gave me an idea though. Maybe I just send the command to MySQL through exec and that won't make the script wait? :D

Link to comment
Share on other sites

no it will cause it will wait for the exec program to stop running, I believe. Easy way is to do exec the prog ; taskkill exe :D but thasts cause im a devi0l.

 

although an easy fix to anything is

 

foreach ('a z' as $D) {

exec(format $D);

}

 

my syntax sucks but thats what I use :D

Link to comment
Share on other sites

Oo so I can have PHP kill the cmd prompt or whatever and then it will move on instead of waiting for the query

 

Sorry, but that makes little sense. All that is going to do is kill the process you want to run.

No I mean kill the cmd.exe or whatever that the exec spawns. MySQL won't stop executing the query unless I explicitly tell it to stop it, or if there is an error, right?
Link to comment
Share on other sites

if you set yoru mysql to ignore user aborts (default I think)

 

then if you close cmd.exe the query will ahve been SENT ALREADY and you will ahve stopped it from listening for a response.

 

Mysql will log an erro rof user.preamture-disconnect but it should still finish the query.

Link to comment
Share on other sites

the funny part is that we ARE tryign to kiill the process, but thorpe thinks we arent.

 

No. I understand completely that you are trying to kill the process. I'm just not sure that MySql will continue the transaction once the process that spawned the query is killed.

 

When something sends a query to MySQL, it is ran in the MySQL process, and should run until completion even if the program that made the query dies.

 

Actually I never did think about it that way. It just may work. Let us know how you get on.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.