Skip to content

Commit 34eaee6

Browse files
authored
Merge pull request #38 from true-async/36-add-dockerfile
36 add dockerfile
2 parents 5a644b9 + a22dcdc commit 34eaee6

File tree

4 files changed

+161
-2
lines changed

4 files changed

+161
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
## [0.3.0] - TBD
1111

1212
### Added
13+
- Docker support with multi-stage build (Ubuntu 24.04, libuv 1.49, curl 8.10)
14+
- PDO MySQL and MySQLi async support
1315
- **Multiple Callbacks Per Event Support**: Complete redesign of waker trigger system to support multiple callbacks on a single event
1416
- Modified `zend_async_waker_trigger_s` structure to use flexible array member with dynamic capacity
1517
- Added `waker_trigger_create()` and `waker_trigger_add_callback()` helper functions for efficient memory management

Dockerfile

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# ===== True Async PHP (Linux x64 ZTS Release) =====
2+
# Multi-stage build: builder + runtime
3+
4+
# ---------- BUILDER STAGE ----------
5+
FROM ubuntu:24.04 AS builder
6+
7+
# ---------- 1. System toolchain & libraries ----------
8+
RUN apt-get update && apt-get install -y \
9+
autoconf bison build-essential curl re2c git \
10+
cmake ninja-build wget dos2unix \
11+
libxml2-dev libssl-dev pkg-config libargon2-dev \
12+
libcurl4-openssl-dev libedit-dev libreadline-dev \
13+
libsodium-dev libsqlite3-dev libonig-dev libzip-dev \
14+
libpng-dev libjpeg-dev libwebp-dev libfreetype6-dev \
15+
libgmp-dev libldap2-dev libsasl2-dev libpq-dev \
16+
libmysqlclient-dev libbz2-dev libenchant-2-dev \
17+
libffi-dev libgdbm-dev liblmdb-dev libsnmp-dev \
18+
libtidy-dev libxslt1-dev libicu-dev libpsl-dev
19+
20+
# ---------- 2. libuv 1.49 ----------
21+
RUN wget -q https://github.com/libuv/libuv/archive/v1.49.0.tar.gz \
22+
&& tar -xf v1.49.0.tar.gz \
23+
&& cd libuv-1.49.0 && mkdir build && cd build \
24+
&& cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF \
25+
&& ninja && ninja install && ldconfig \
26+
&& cd / && rm -rf libuv*
27+
28+
# ---------- 3. curl 8.10 ----------
29+
RUN wget -q https://github.com/curl/curl/releases/download/curl-8_10_1/curl-8.10.1.tar.gz \
30+
&& tar -xf curl-8.10.1.tar.gz \
31+
&& cd curl-8.10.1 \
32+
&& ./configure --prefix=/usr/local --with-openssl --enable-shared --disable-static \
33+
&& make -j$(nproc) && make install && ldconfig \
34+
&& cd / && rm -rf curl*
35+
36+
# ---------- 4. PHP sources ----------
37+
RUN git clone --depth=1 --branch=true-async-stable https://github.com/true-async/php-src /usr/src/php-src
38+
39+
# ---------- 5. Copy async extension (Dockerfile in extension root) ----------
40+
RUN mkdir -p /usr/src/php-src/ext/async
41+
COPY . /usr/src/php-src/ext/async
42+
43+
# ---------- 5.1. Fix Windows line endings in config.m4 ----------
44+
RUN dos2unix /usr/src/php-src/ext/async/config.m4
45+
46+
WORKDIR /usr/src/php-src
47+
48+
# ---------- 6. Configure & build PHP ----------
49+
RUN ./buildconf --force && \
50+
./configure \
51+
--prefix=/usr/local \
52+
--with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd \
53+
--with-pgsql --with-pdo-pgsql --with-pdo-sqlite \
54+
--without-pear \
55+
--enable-gd --with-jpeg --with-webp --with-freetype \
56+
--enable-exif --with-zip --with-zlib \
57+
--enable-soap --enable-xmlreader --with-xsl --with-tidy --with-libxml \
58+
--enable-sysvsem --enable-sysvshm --enable-shmop --enable-pcntl \
59+
--with-readline \
60+
--enable-mbstring --with-curl --with-gettext \
61+
--enable-sockets --with-bz2 --with-openssl --with-gmp \
62+
--enable-bcmath --enable-calendar --enable-ftp --with-enchant \
63+
--enable-sysvmsg --with-ffi --enable-dba --with-lmdb --with-gdbm \
64+
--with-snmp --enable-intl --with-ldap --with-ldap-sasl \
65+
--enable-werror \
66+
--with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d \
67+
--disable-debug --enable-zts \
68+
--enable-async && \
69+
make -j$(nproc) && make install
70+
71+
# ---------- 7. Minimal runtime setup ----------
72+
RUN mkdir -p /etc/php.d && echo "opcache.enable_cli=1" > /etc/php.d/opcache.ini
73+
74+
# ---------- RUNTIME STAGE ----------
75+
FROM ubuntu:24.04 AS runtime
76+
77+
# Install only runtime dependencies (no build tools)
78+
RUN apt-get update && apt-get install -y --no-install-recommends \
79+
libxml2 libssl3 libargon2-1 \
80+
libcurl4 libedit2 libreadline8 \
81+
libsodium23 libsqlite3-0 libonig5 libzip4 \
82+
libpng16-16 libjpeg8 libwebp7 libfreetype6 \
83+
libgmp10 libldap2 libsasl2-2 libpq5 \
84+
libmysqlclient21 libbz2-1.0 libenchant-2-2 \
85+
libffi8 libgdbm6 liblmdb0 libsnmp40 \
86+
libtidy5deb1 libxslt1.1 libicu74 libpsl5 \
87+
ca-certificates \
88+
&& rm -rf /var/lib/apt/lists/*
89+
90+
# Copy built PHP and libraries from builder stage
91+
COPY --from=builder /usr/local /usr/local
92+
COPY --from=builder /etc/php.d /etc/php.d
93+
94+
# Update library cache
95+
RUN ldconfig
96+
97+
# Set PATH
98+
ENV PATH="/usr/local/bin:/usr/local/sbin:$PATH"
99+
100+
# Verify PHP installation
101+
RUN php -v
102+
103+
WORKDIR /app
104+
105+
CMD ["php", "-v"]

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ tightly integrated at the core level.
3131
PHP TRUE ASYNC is supported for PHP 8.5.0 and later.
3232
`LibUV` is the primary reactor implementation for this extension.
3333

34+
### Docker (for tests)
35+
36+
```bash
37+
# Build the image
38+
docker build -t true-async-php .
39+
40+
# Run interactively
41+
docker run -it true-async-php bash
42+
43+
# Check TrueAsync module
44+
docker run --rm true-async-php php -m | grep TrueAsync
45+
```
46+
3447
### Requirements
3548

3649
- **PHP 8.5.0+**
@@ -160,6 +173,14 @@ Please see the [LibUV installation guide](https://github.com/libuv/libuv) for mo
160173
- `gethostbyaddr()` - resolve IP address to hostname
161174
- `gethostbynamel()` - get list of IP addresses for hostname
162175

176+
### Database Functions
177+
- **PDO MySQL** - async-compatible PDO operations
178+
- `PDO::__construct()`, `PDO::prepare()`, `PDO::exec()` - non-blocking
179+
- `PDOStatement::execute()`, `PDOStatement::fetch()` - async data access
180+
- **MySQLi** - async-compatible MySQLi operations
181+
- `mysqli_connect()`, `mysqli_query()`, `mysqli_prepare()` - non-blocking
182+
- `mysqli_stmt_execute()`, `mysqli_fetch_*()` - async result fetching
183+
163184
### CURL Functions
164185
- `curl_exec()` - execute cURL request
165186
- `curl_multi_exec()` - execute multiple cURL handles
@@ -289,6 +310,39 @@ $elapsed = microtime(true) - $start;
289310
echo "All requests completed in: " . round($elapsed, 3) . "s\n";
290311
```
291312

313+
### Async Database Operations
314+
315+
```php
316+
<?php
317+
318+
// Concurrent database queries with PDO MySQL
319+
Async\spawn(function() {
320+
$pdo = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
321+
322+
// All operations are non-blocking in async context
323+
$stmt = $pdo->prepare("SELECT * FROM users WHERE active = ?");
324+
$stmt->execute([1]);
325+
326+
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
327+
echo "User: {$row['name']}\n";
328+
}
329+
});
330+
331+
// MySQLi concurrent operations
332+
Async\spawn(function() {
333+
$mysqli = new mysqli('localhost', $user, $pass, 'test');
334+
335+
// Non-blocking query execution
336+
$result = $mysqli->query("SELECT COUNT(*) as total FROM orders");
337+
$row = $result->fetch_assoc();
338+
echo "Total orders: {$row['total']}\n";
339+
340+
$mysqli->close();
341+
});
342+
343+
echo "Database queries started\n";
344+
```
345+
292346
### Process Execution
293347

294348
```php

TODO.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
* For the internal context, it’s necessary to add the ability for
2-
it to operate even before coroutines exist at all.

0 commit comments

Comments
 (0)