diff --git a/CHANGELOG.md b/CHANGELOG.md index e736877..4577c03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.3.0] - TBD ### Added +- Docker support with multi-stage build (Ubuntu 24.04, libuv 1.49, curl 8.10) +- PDO MySQL and MySQLi async support - **Multiple Callbacks Per Event Support**: Complete redesign of waker trigger system to support multiple callbacks on a single event - Modified `zend_async_waker_trigger_s` structure to use flexible array member with dynamic capacity - Added `waker_trigger_create()` and `waker_trigger_add_callback()` helper functions for efficient memory management diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e2c9eb1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,105 @@ +# ===== True Async PHP (Linux x64 ZTS Release) ===== +# Multi-stage build: builder + runtime + +# ---------- BUILDER STAGE ---------- +FROM ubuntu:24.04 AS builder + +# ---------- 1. System toolchain & libraries ---------- +RUN apt-get update && apt-get install -y \ + autoconf bison build-essential curl re2c git \ + cmake ninja-build wget dos2unix \ + libxml2-dev libssl-dev pkg-config libargon2-dev \ + libcurl4-openssl-dev libedit-dev libreadline-dev \ + libsodium-dev libsqlite3-dev libonig-dev libzip-dev \ + libpng-dev libjpeg-dev libwebp-dev libfreetype6-dev \ + libgmp-dev libldap2-dev libsasl2-dev libpq-dev \ + libmysqlclient-dev libbz2-dev libenchant-2-dev \ + libffi-dev libgdbm-dev liblmdb-dev libsnmp-dev \ + libtidy-dev libxslt1-dev libicu-dev libpsl-dev + +# ---------- 2. libuv 1.49 ---------- +RUN wget -q https://github.com/libuv/libuv/archive/v1.49.0.tar.gz \ + && tar -xf v1.49.0.tar.gz \ + && cd libuv-1.49.0 && mkdir build && cd build \ + && cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF \ + && ninja && ninja install && ldconfig \ + && cd / && rm -rf libuv* + +# ---------- 3. curl 8.10 ---------- +RUN wget -q https://github.com/curl/curl/releases/download/curl-8_10_1/curl-8.10.1.tar.gz \ + && tar -xf curl-8.10.1.tar.gz \ + && cd curl-8.10.1 \ + && ./configure --prefix=/usr/local --with-openssl --enable-shared --disable-static \ + && make -j$(nproc) && make install && ldconfig \ + && cd / && rm -rf curl* + +# ---------- 4. PHP sources ---------- +RUN git clone --depth=1 --branch=true-async-stable https://github.com/true-async/php-src /usr/src/php-src + +# ---------- 5. Copy async extension (Dockerfile in extension root) ---------- +RUN mkdir -p /usr/src/php-src/ext/async +COPY . /usr/src/php-src/ext/async + +# ---------- 5.1. Fix Windows line endings in config.m4 ---------- +RUN dos2unix /usr/src/php-src/ext/async/config.m4 + +WORKDIR /usr/src/php-src + +# ---------- 6. Configure & build PHP ---------- +RUN ./buildconf --force && \ + ./configure \ + --prefix=/usr/local \ + --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd \ + --with-pgsql --with-pdo-pgsql --with-pdo-sqlite \ + --without-pear \ + --enable-gd --with-jpeg --with-webp --with-freetype \ + --enable-exif --with-zip --with-zlib \ + --enable-soap --enable-xmlreader --with-xsl --with-tidy --with-libxml \ + --enable-sysvsem --enable-sysvshm --enable-shmop --enable-pcntl \ + --with-readline \ + --enable-mbstring --with-curl --with-gettext \ + --enable-sockets --with-bz2 --with-openssl --with-gmp \ + --enable-bcmath --enable-calendar --enable-ftp --with-enchant \ + --enable-sysvmsg --with-ffi --enable-dba --with-lmdb --with-gdbm \ + --with-snmp --enable-intl --with-ldap --with-ldap-sasl \ + --enable-werror \ + --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d \ + --disable-debug --enable-zts \ + --enable-async && \ + make -j$(nproc) && make install + +# ---------- 7. Minimal runtime setup ---------- +RUN mkdir -p /etc/php.d && echo "opcache.enable_cli=1" > /etc/php.d/opcache.ini + +# ---------- RUNTIME STAGE ---------- +FROM ubuntu:24.04 AS runtime + +# Install only runtime dependencies (no build tools) +RUN apt-get update && apt-get install -y --no-install-recommends \ + libxml2 libssl3 libargon2-1 \ + libcurl4 libedit2 libreadline8 \ + libsodium23 libsqlite3-0 libonig5 libzip4 \ + libpng16-16 libjpeg8 libwebp7 libfreetype6 \ + libgmp10 libldap2 libsasl2-2 libpq5 \ + libmysqlclient21 libbz2-1.0 libenchant-2-2 \ + libffi8 libgdbm6 liblmdb0 libsnmp40 \ + libtidy5deb1 libxslt1.1 libicu74 libpsl5 \ + ca-certificates \ + && rm -rf /var/lib/apt/lists/* + +# Copy built PHP and libraries from builder stage +COPY --from=builder /usr/local /usr/local +COPY --from=builder /etc/php.d /etc/php.d + +# Update library cache +RUN ldconfig + +# Set PATH +ENV PATH="/usr/local/bin:/usr/local/sbin:$PATH" + +# Verify PHP installation +RUN php -v + +WORKDIR /app + +CMD ["php", "-v"] diff --git a/README.md b/README.md index e87568e..1576cfe 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,19 @@ tightly integrated at the core level. PHP TRUE ASYNC is supported for PHP 8.5.0 and later. `LibUV` is the primary reactor implementation for this extension. +### Docker (for tests) + +```bash +# Build the image +docker build -t true-async-php . + +# Run interactively +docker run -it true-async-php bash + +# Check TrueAsync module +docker run --rm true-async-php php -m | grep TrueAsync +``` + ### Requirements - **PHP 8.5.0+** @@ -160,6 +173,14 @@ Please see the [LibUV installation guide](https://github.com/libuv/libuv) for mo - `gethostbyaddr()` - resolve IP address to hostname - `gethostbynamel()` - get list of IP addresses for hostname +### Database Functions +- **PDO MySQL** - async-compatible PDO operations + - `PDO::__construct()`, `PDO::prepare()`, `PDO::exec()` - non-blocking + - `PDOStatement::execute()`, `PDOStatement::fetch()` - async data access +- **MySQLi** - async-compatible MySQLi operations + - `mysqli_connect()`, `mysqli_query()`, `mysqli_prepare()` - non-blocking + - `mysqli_stmt_execute()`, `mysqli_fetch_*()` - async result fetching + ### CURL Functions - `curl_exec()` - execute cURL request - `curl_multi_exec()` - execute multiple cURL handles @@ -289,6 +310,39 @@ $elapsed = microtime(true) - $start; echo "All requests completed in: " . round($elapsed, 3) . "s\n"; ``` +### Async Database Operations + +```php +prepare("SELECT * FROM users WHERE active = ?"); + $stmt->execute([1]); + + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { + echo "User: {$row['name']}\n"; + } +}); + +// MySQLi concurrent operations +Async\spawn(function() { + $mysqli = new mysqli('localhost', $user, $pass, 'test'); + + // Non-blocking query execution + $result = $mysqli->query("SELECT COUNT(*) as total FROM orders"); + $row = $result->fetch_assoc(); + echo "Total orders: {$row['total']}\n"; + + $mysqli->close(); +}); + +echo "Database queries started\n"; +``` + ### Process Execution ```php diff --git a/TODO.md b/TODO.md index ba2cd86..e69de29 100644 --- a/TODO.md +++ b/TODO.md @@ -1,2 +0,0 @@ -* For the internal context, it’s necessary to add the ability for -it to operate even before coroutines exist at all. \ No newline at end of file