PHP MySQLi Asynchronous Queries with

后端 未结 1 749

I am trying to use asynchronous queries via PHP MySQLi.

The following code has been simplified, the original is code is too verbose to list here because of class dep

1条回答
  •  一生所求
    2020-12-29 12:29

    Unfortunately, the mysqli documentation is rather lacking, particularly in this regard. The issue is that the 'async' mode is a mysql client-side behavior, and not part of the client/server protocol. That is, you can still only have one query (or multi-query, I suppose) running on a connection at a given time. MYSQLI_ASYNC only specifies that your application shouldn't block while waiting for the query results. Results have to be collected later with mysqli_poll().

    In your example, $query_1 is synchronous, so is completely done by the time it returns and assigns to $mysqli_stmt_obj. $query_2 is started asynchronously on $mysqli_handle successfully, and returns without waiting for the results. By the time the script gets to $query_3, it still has a pending result waiting for $query_2. Thus, it attempts to send another query before finishing the last one, giving you 'commands out of sync'.

    0 讨论(0)
提交回复
热议问题