Skip to content

36 add dockerfile #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
105 changes: 105 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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+**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -289,6 +310,39 @@ $elapsed = microtime(true) - $start;
echo "All requests completed in: " . round($elapsed, 3) . "s\n";
```

### Async Database Operations

```php
<?php

// Concurrent database queries with PDO MySQL
Async\spawn(function() {
$pdo = new PDO('mysql:host=localhost;dbname=test', $user, $pass);

// All operations are non-blocking in async context
$stmt = $pdo->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
Expand Down
2 changes: 0 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -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.
Loading