mojahed/php-multiquery

Parallel MySQL query execution for raw PHP projects - Run multiple MySQL queries in parallel for efficient execution.

Maintainers

Package info

github.com/md-mojahed/php-multiquery

pkg:composer/mojahed/php-multiquery

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-05-17 13:36 UTC

This package is auto-updated.

Last update: 2026-05-17 13:39:17 UTC


README

Parallel MySQL query execution for raw PHP projects using the msquery.

No framework required. PHP 7.4+.

Requirements

  • PHP 7.4+
  • msquery installed on server

Installation

composer require mojahed/php-multiquery

Binary Setup

cp msquery-linux-amd64 /usr/local/bin/msquery
chmod +x /usr/local/bin/msquery

Usage

use Mojahed\Raw\MultiQuery;

$results = MultiQuery::setConfig([
    'binary'   => '/usr/local/bin/msquery',
    'host'     => '127.0.0.1',
    'port'     => '3306',
    'user'     => 'root',
    'pass'     => 'secret',
    'database' => 'my_database',
    'timeout'  => 30,
    'throw'    => true,
])->run([
    'users'   => "SELECT COUNT(*) as total FROM users",
    'orders'  => "SELECT COUNT(*) as total FROM orders",
    'revenue' => "SELECT SUM(amount) as total FROM payments",
]);

$results['users']   // [['total' => 150]]
$results['orders']  // [['total' => 320]]
$results['revenue'] // [['total' => 250000]]

Reuse Instance

$mq = MultiQuery::setConfig([...]);

$stats   = $mq->run([...]);
$reports = $mq->run([...]);

Error Handling

use Mojahed\Raw\Exceptions\MultiQueryException;

try {
    $results = MultiQuery::setConfig([...])->run([
        'users'  => "SELECT COUNT(*) as total FROM users",
        'broken' => "SELECT * FROM non_existing_table",
    ]);
} catch (MultiQueryException $e) {
    $e->getFailedIndex();  // which query failed
    $e->getErrorString();  // MySQL error message
    $e->getResults();      // all raw results
}

Config Options

Option Default Description
binary /usr/local/bin/msquery Path to binary
host 127.0.0.1 MySQL host
port 3306 MySQL port
user - MySQL username
pass - MySQL password
database - Database name
timeout 30 MySQL connection timeout (seconds)
throw true Throw on failure