This configuration allows you to run TrueAsync PHP in FPM mode with Nginx web server.
Dockerfile- main Dockerfile for building PHP-FPMnginx.conf- Nginx configurationphp-fpm.conf- main PHP-FPM configurationwww.conf- PHP-FPM pool configurationsupervisord.conf- supervisor configuration for process managementdocker-compose.yml- Docker Compose file for easy deployment
# Create directory for your application
mkdir -p app
echo '<?php phpinfo(); ?>' > app/index.php
# Start the container
docker-compose up --build
# Open in browser: http://localhost:8080# Build the image
docker build -t trueasync-fpm .
# Run the container
docker run -d -p 8080:80 --name trueasync-fpm trueasync-fpm
# Open in browser: http://localhost:8080The container includes several test files:
- http://localhost:8080/ - Landing page with examples
- http://localhost:8080/phpinfo.php - Full PHPInfo
- http://localhost:8080/async-test.php - Basic TrueAsync tests
- http://localhost:8080/async-parallel.php - Parallel execution demo
- http://localhost:8080/async-sleep.php - Async sleep demo
- http://localhost:8080/async-scraper.php - Web scraping demo
Or using curl:
# Check phpinfo
curl http://localhost:8080/phpinfo.php
# Test TrueAsync
curl http://localhost:8080/async-test.phpCreate a file app/my-async-test.php:
<?php
use function Async\spawn;
use function Async\await;
use function Async\awaitAll;
use function Async\delay;
echo "Starting async operations...\n";
// Example 1: Simple spawn and await
$coroutine = spawn(function() {
delay(1000); // 1 second
return "Task completed!";
});
$result = await($coroutine);
echo "$result\n";
// Example 2: Parallel execution
$coroutines = [
spawn(fn() => delay(1000) ?? "Task 1"),
spawn(fn() => delay(1000) ?? "Task 2"),
spawn(fn() => delay(1000) ?? "Task 3"),
];
[$results, $exceptions] = awaitAll($coroutines);
print_r($results);
echo "All done!\n";Test it: http://localhost:8080/my-async-test.php
PHP-FPM Pool (www.conf)
Main process parameters:
pm = dynamic
pm.max_children = 50 # Maximum processes
pm.start_servers = 5 # Starting number
pm.min_spare_servers = 5 # Minimum idle processes
pm.max_spare_servers = 35 # Maximum idle processesConfiguration is located in nginx.conf. Main settings:
- Document root:
/var/www/html - Socket:
/run/php-fpm/php-fpm.sock - Timeouts increased to 300 seconds for async operations
Add your custom settings in php.ini:
# In docker-compose.yml, uncomment:
volumes:
- ./custom-php.ini:/etc/php.d/custom.iniExample custom-php.ini:
max_execution_time = 300
memory_limit = 256M
upload_max_filesize = 50M
post_max_size = 50MView logs:
# All logs
docker-compose logs -f
# PHP-FPM only
docker exec -it trueasync-fpm tail -f /var/log/php-fpm/error.log
# Nginx only
docker exec -it trueasync-fpm tail -f /var/log/nginx/error.log# Bash in container
docker exec -it trueasync-fpm bash
# Check PHP version
docker exec -it trueasync-fpm php -v
# Check extensions
docker exec -it trueasync-fpm php -m | grep asyncFor production environments, it's recommended to:
- Disable error display (custom-php.ini):
display_errors = Off
display_startup_errors = Off
log_errors = On- Increase OPcache:
opcache.enable=1
opcache.memory_consumption=256
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=20000- Configure process limits in
www.conf:
pm.max_children = 100
pm.start_servers = 10
pm.min_spare_servers = 10
pm.max_spare_servers = 50- SSL/TLS - add reverse proxy or modify nginx.conf
# Check logs
docker logs trueasync-fpm
# Check configuration
docker exec -it trueasync-fpm php-fpm -t# Check if PHP-FPM is running
docker exec -it trueasync-fpm ps aux | grep php-fpm
# Check socket
docker exec -it trueasync-fpm ls -la /run/php-fpm/# Check file ownership
docker exec -it trueasync-fpm ls -la /var/www/html
# Fix if needed
docker exec -it trueasync-fpm chown -R www-data:www-data /var/www/html# Stop
docker-compose down
# Stop and remove volumes
docker-compose down -v
# Full cleanup
docker-compose down -v --rmi all