开发者

Can PHP issue multi processed mysql queries in an Apache environment?

I 开发者_如何学Chave a single database server with 4 cores and a web server running PHP. I want one PHP script to be able to issue queries to the database server such that they execute in parallel on the database server, one on each mysqld process. Typically in PHP you do this:

$sql = new mysqli( [insert connection parameters] );
$sql->query( "SELECT 'Complex Query A'" );
$sql->query( "SELECT 'Complex Query B'" );
$sql->query( "SELECT 'Complex Query C'" );
$sql->query( "SELECT 'Complex Query D'" );

But these run serially and only utilize one mysqld process. In this application, each query (A through D) is processing a different part of the data, but working on the same set of InnoDB tables.

One possible solution is to make AJAX calls to apache to break it down into sub-scripts that might run in parallel, but I'm guessing that Apache will process those ajax calls sequentially with one httpd process per client.

Is there a way to achieve this? Does anyone have experience with the mysqlnd MYSQLI_ASYNC features? Can they work in parallel with a single database server and mysqli connection?

Purpose: we run real-time analytic tools that generate graphs and I'd like to take advantage of the processing power on our database to speed up the queries which take time.


What you need is asynchronous query execution. It is possible starting with PHP 5.3 when you have the new mysqlnd driver - then you are able to pass MYSQLI_ASYNC flag to query() method. Script execution will continue without waiting for your query to finish. There is a nice usage example available in PHP manual in comments for the poll() method.

You will need a separate MySQL connection for each query that you want to execute in parallel.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜