react/mysql
Async MySQL client for ReactPHP. Pure PHP implementation of the MySQL protocol with no extensions required. Connect via URI, run queries with promises, stream results, and manage connection lifecycle (ping/quit/close).
Start by installing the package via Composer: composer require react/mysql. The core entry point is React\Mysql\MysqlClient, instantiated with a DSN-style connection URI (e.g., 'user:pass@localhost/db'). Your first use case will likely be executing simple SELECT queries — see the Quickstart example in the README. Use query() for small result sets (buffers full result in memory), and queryStream() for large datasets (streams row-by-row). Both return promises or streams compatible with ReactPHP’s async model.
MysqlClient once per service/service class; the client queues queries while establishing the connection and reuses idle connections (default idle timeout = 1ms). Group related operations using then() chains or Promise::all() for concurrent reads, but be mindful that the MySQL protocol is sequential — queries still execute in order per connection.$mysql->query('SELECT * FROM users WHERE id = ?', [$id])) to avoid injection and improve safety.queryStream() with event handlers (on('data', ...)) or pipe to writable streams (e.g., format + log pipeline). Ensure the destination stream processes data quickly to avoid server-side timeouts.BEGIN, DML statements, and COMMIT/ROLLBACK using promises (sequencing is critical — never interleave transactions across queries on the same client instance).Connection refused) but be cautious with transaction-aware operations.?idle=30.0 to reduce handshake overhead — but avoid keeping idle connections open across forked processes.commit()/rollback() and avoid concurrent commands during transaction blocks.utf8mb4, but legacy DBs may require explicit ?charset=utf8 — mismatch can cause silent truncation or errors with 4-byte emojis.React\Socket\Connector for proxy, bindto, or DNS overrides. TLS handshake failures often mask as connection timeouts — validate certs carefully in dev.MYSQL_DEBUG environment variable (per ReactPHP convention) to inspect raw protocol traffic. Add middleware to log slow queries (wrap query() with timing).0.6.x branch for stable production use unless you plan to contribute or tolerate breaking changes. Check changelog for migration notes between minor versions.How can I help you explore Laravel packages today?