1

Firstly I'm using the deprecated mysql functions (instead of mysqli) knowingly, so please do not tell me I should change to mysqli.

My question is: if I want to do an INSERT or UPDATE and continue processing the PHP script immediately, without waiting for MySQL to complete the task, can I use mysql_unbuffered_query (is that what is does?) or if not, how can I achieve that?

4
  • @MikeB, My question is actually whether mysql_unbuffered_query does this or not, so it is not the same question as that question does not answer my question. Commented Mar 18, 2013 at 13:13
  • 1
    Then your answer is no. mysql_unbuffer_query() still waits for the query to execute, it just doesn't go through the trouble of fetching the results. php.net/manual/en/mysqlinfo.concepts.buffering.php Commented Mar 18, 2013 at 13:14
  • If you'le interested I wrote on how to execute queries in the background. Maybe it will help you or give you an idea: hancic.info/run-sql-queries-in-the-background-with-php Commented Mar 18, 2013 at 13:16
  • 2
    @jan You could have just posted the link to gearman here, would save a lot of time in reading your article that just says that you used it. Commented Mar 18, 2013 at 13:19

2 Answers 2

8

Sorry to break this to you :)

If you use mysqli, with the mysqlnd driver, you can pass a MYSQLI_ASYNC option to the query() method. Unbuffered queries do not help here.

Later on you can use the poll() and reap_async_query() to get to the result.

Sign up to request clarification or add additional context in comments.

3 Comments

I knew someone would insist on mentioning mysqi even though I began my post specifically mentioning that I DO NOT CARE.
@Alasdair: Well I wanted to point it out, because that's the first place where true async queries are working. If you don't care about the security problems (which is pretty dumb), then this may still be a good reason to upgrade anyway.
@Alasdair Just as a hint, you can also use mysqli just in some small part, without updating your whole application to use it :)
4

You can use INSERT...DELAYED for asynchronous insertions (1). I do not believe you can do asynchronous UPDATE's without resorting to spawning another process (2).

(1) but is not available to InnoDB tables

(2) if sticking to the old mysql extension is an absolute requirement

1 Comment

Note that this will not work on all storage engines.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.