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?

Alasdair
  • 13,348
  • 18
  • 82
  • 138
  • @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. – Alasdair Mar 18 '13 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. http://www.php.net/manual/en/mysqlinfo.concepts.buffering.php – Mike B Mar 18 '13 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: http://hancic.info/run-sql-queries-in-the-background-with-php – Jan Hančič Mar 18 '13 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. – Hugo Delsing Mar 18 '13 at 13:19

2 Answers2

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.

Toto
  • 2,329
  • 22
  • 40
Evert
  • 93,428
  • 18
  • 118
  • 189
  • I knew someone would insist on mentioning `mysqi` even though I began my post specifically mentioning that I DO NOT CARE. – Alasdair Mar 18 '13 at 13:17
  • @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. – Evert Mar 18 '13 at 13:26
  • 1
    @Alasdair Just as a hint, you can also use mysqli just in some small part, without updating your whole application to use it :) – NikiC Mar 18 '13 at 15:43
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

RandomSeed
  • 29,301
  • 6
  • 52
  • 87