PHP ile Asenkron Programlama: Swoole & PHP 8.4 | Asynchronous Programming with PHP: Swoole & PHP 8.4
TR: Bu proje, PHPKonf 2025 konferansı için hazırlanmış "PHP ile Asenkron Programlama: Swoole & PHP 8.4" başlıklı sunum için geliştirilmiş demo uygulamalarını içermektedir. OpenSwoole 25 ve PHP 8.4 kullanarak asenkron programlama, HTTP sunucu oluşturma ve gerçek zamanlı oyun geliştirme örnekleri sunmaktadır. Sunumun PDF dosyası
presentation.pdfolarak projeye dahil edilmiştir.
EN: This project contains demo applications developed for the presentation titled "Asynchronous Programming with PHP: Swoole & PHP 8.4" prepared for PHPKonf 2025 conference. It demonstrates asynchronous programming, HTTP server creation, and real-time game development examples using OpenSwoole 25 and PHP 8.4. The presentation PDF file is included in the project as
presentation.pdf.
presentation.pdf- PHPKonf 2025 presentation slideshttp_server.php- Simple HTTP server examplexox_server.php- Real-time XOX (Tic-tac-toe) game serverxox_client.html- Game client interfaceREADME.md- Installation and usage guide
To run these demo applications, you'll need:
- PHP 8.4.X or higher
- OpenSwoole 25.X extension
After completing the installation process, you can run the demonstration projects:
A simple HTTP server implementation demonstrating basic OpenSwoole functionality.
Start the server:
php http_server.phpTest the server:
- Open http://localhost:9051 in your browser
- Monitor server logs in the CLI output
An advanced real-time multiplayer game demonstrating WebSocket capabilities and concurrent connection handling.
Start the game server:
php xox_server.phpPlay the game:
- Open
xox_client.htmlin your web browser - Use multiple browser tabs to simulate different players
- Enjoy real-time multiplayer tic-tac-toe!
Choose your operating system for detailed installation instructions:
- Windows Subsystem for Linux (WSL) must be installed
- Available from Microsoft Store
Install Ubuntu using Windows Subsystem for Linux via PowerShell:
wsl --install -d UbuntuUpdate the Ubuntu system and add the PHP repository:
sudo apt update
sudo apt install -y software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt updateInstall PHP 8.4 with all required extensions:
sudo apt install -y php8.4 php8.4-cli php8.4-common php8.4-dev php8.4-mysql php8.4-pgsql php8.4-xml php8.4-mbstring php8.4-curl php-pear build-essential libcurl4-openssl-devVerify PHP and PECL installations:
php -v
pecl version
sudo pecl channel-update pecl.php.netInstall the OpenSwoole extension via PECL:
pecl install openswooleVerify the extension installation:
find /usr/lib/php/ -name openswoole.soCreate the configuration file:
sudo bash -c "cat > /etc/php/8.4/mods-available/openswoole.ini << EOF
; Configuration for OpenSwoole
; priority=30
extension=openswoole
EOF"Enable the extension:
sudo phpenmod -s cli openswooleConfirm OpenSwoole is properly installed:
php -m | grep openswooleCreate a symbolic link for easy access to Windows files:
Note: Requires creating a
C:\WSLdirectory first
ln -s /mnt/c/WSL ~/wsl- Homebrew must be installed on your system
- Visit https://brew.sh/ for installation instructions
Update Homebrew and install PHP:
brew update
brew install phpCheck PHP and PECL versions:
which php && php -v
which pecl && pecl versionSet required environment variables for OpenSwoole compilation:
export CPPFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix pcre2)/include"
export LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix pcre2)/lib"
export PKG_CONFIG_PATH="$(brew --prefix openssl)/lib/pkgconfig:$(brew --prefix pcre2)/lib/pkgconfig"Set up required folder permissions for PECL:
Important: The folder name "20240924" may vary depending on your PHP version. Verify the correct folder name.
Note: Never run Homebrew, PECL, or PHP commands as root user.
sudo chown -R $(whoami) /opt/homebrew/
sudo chown -R $(whoami) /private/tmp/pear
mkdir -p /opt/homebrew/lib/php/pecl/20240924Install the OpenSwoole extension:
pecl install openswooleAdd OpenSwoole extension to PHP configuration:
echo "extension=openswoole" > /opt/homebrew/etc/php/8.4/conf.d/99-openswoole.iniConfirm OpenSwoole is properly installed:
php -m | grep openswooleIf port 9501 is occupied, terminate conflicting processes:
kill -9 $(lsof -t -i :9501)