Download the PHP package fiber-interop/mysqli without Composer
On this page you can find all versions of the php package fiber-interop/mysqli. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fiber-interop/mysqli
More information about fiber-interop/mysqli
Files in fiber-interop/mysqli
Package mysqli
Short Description Cooperative mysqli queries for fiber-interop/api: fiber\mysqli\query() and start() on any adapter, with native drivers where the runtime has one.
License MIT
Informations about the package mysqli
fiber-interop/mysqli
Cooperative mysqli queries for fiber-interop/api: inside
fiber\run() a query suspends only the calling task, on whichever adapter is installed.
API
fiber\mysqli\query(\mysqli $m, string $sql, int $resultMode = MYSQLI_STORE_RESULT): \mysqli_result|bool— exactly$m->query()'s contract: amysqli_resultfor result sets,truefor other statements,falseon failure with$m->errno/$m->errorset, or amysqli_sql_exceptionthrown whenmysqli_report()asks for exceptions (the default since PHP 8.1). The connection stays usable after an error. Outsidefiber\run()it is a plain blocking$m->query().fiber\mysqli\start(...same arguments): object— sends the query and returns an awaitable (repeatablefiber\await()) resolving to whatquery()returns.query()isawait(start()).fiber\mysqli\Driver— one method,start(\mysqli $m, string $sql, int $resultMode): object.fiber\mysqli\setup(Driver),fiber\mysqli\register(callable $factory, string $package),fiber\mysqli\driver()— same semantics as the api's adapter registry:setup()wins; a single registered candidate is instantiated lazily; two candidates withoutsetup()throwfiber\NotConfiguredException; with none, the genericPollDriveris used.
Adapters register a native driver from their register.php exactly as for
fiber-interop/curl: by writing
fiber\mysqli\Registry::$candidates[...] behind interface_exists(\fiber\mysqli\Driver::class) and
their own runtime check.
One query per connection
The MySQL protocol allows one query in flight per connection. start() on a connection that is
still busy does not fail: the query is queued and sent when the previous one completes, so two
tasks sharing a connection run their queries one after the other. For parallelism, use one
connection per concurrent task.
How it waits: polling, honestly
PollDriver sends with $m->query($sql, MYSQLI_ASYNC) and one poller task calls
mysqli_poll(..., 0, 0) over all in-flight connections, then $m->reap_async_query() for the ready
ones. Between rounds it sleeps with fiber\sleep(): 1 ms after a round in which something completed,
backing off ×1.5 toward 10 ms while nothing does. It stops when no query is in flight.
This is polling. mysqli exposes no file descriptor for a connection (mysqlnd has a PHP stream
internally but does not hand it out), so fiber\readable() cannot be used. The php-src fix is small:
a mysqli_socket() / stream accessor returning the connection's stream, after which the driver could
wait on the fd like pg_socket() allows for PostgreSQL. Native drivers below avoid the polling.
Native drivers
| Runtime | Driver |
|---|---|
| phasync with the phasync extension loaded | FiberInterop\Phasync\MysqliDriver (go(fn() => $m->query(...)); the extension hooks PHP streams, which mysqlnd uses) |
| Swoole / OpenSwoole | FiberInterop\Swoole\MysqliDriver (same; SWOOLE_HOOK_TCP, part of SWOOLE_HOOK_ALL, makes mysqlnd's socket cooperative) |
| Revolt, AMPHP, ReactPHP, phasync without the extension | PollDriver |
Limits
- A timed-out or cancelled
await()does not abort the query; it runs to completion on the server and its result is discarded unless awaited again. Later queries on that connection wait for it. - With
MYSQLI_USE_RESULTthe queue considers the query done when the result is returned, not when it is fully fetched: free or drain an unbuffered result before starting the next query on that connection, as with blocking mysqli ("Commands out of sync" otherwise). - Only
query(). Prepared statements,multi_query()andreal_connect()still block; wrap them in your own task or use a native driver, where they are cooperative too.
Tests
The suite needs a MySQL or MariaDB server; it never shells out to a client. Environment variables
(defaults in parentheses): MYSQLI_HOST (127.0.0.1), MYSQLI_PORT (13307), MYSQLI_USER (root),
MYSQLI_PASSWORD (test). For example:
FI_RUNTIME=revolt|amp|react|phasync|swoole picks the adapter, FI_DRIVER=generic|native the driver.
CI runs every runtime against a mysql:8.4 service container.