phpolygon/php-vio
Composer 安装命令:
pie install phpolygon/php-vio
包简介
PHP extension for GPU rendering (OpenGL, Vulkan, Metal), audio, video recording, streaming, and input
README 文档
README
A PHP extension that brings GPU rendering, audio, video recording, streaming, and input handling to PHP. Foundation layer for the PHPolygon game engine.
Features
- Multi-Backend GPU Rendering — Direct3D 12, Direct3D 11, Metal, Vulkan (MoltenVK), OpenGL 4.1
- 2D Batch Renderer — Rects, circles, lines, sprites, text (z-sorted, up to 4096 items)
- 3D Pipeline — Meshes, shaders, pipelines, textures, uniform/storage buffers
- Shader Toolchain — GLSL to SPIR-V compilation, reflection, cross-compilation
- Audio — Playback via miniaudio (MP3, WAV, FLAC)
- Video Recording — H.264 encoding via FFmpeg (with VideoToolbox HW acceleration)
- Network Streaming — RTMP and SRT via FFmpeg
- Input — Keyboard, mouse, and gamepad support via GLFW
- Headless Mode — Offscreen rendering for tests and visual regression testing
- Plugin System — Extensible output/input/filter plugins
- Cross-Platform — macOS, Linux, Windows
Requirements
- PHP >= 8.5
All native libraries are optional — the extension compiles and runs without them, features are simply unavailable at runtime:
| Library | Feature | Build Flag |
|---|---|---|
| GLFW 3.4 | Windowing, input, gamepad | --with-glfw |
| glslang | GLSL to SPIR-V compilation | --with-glslang |
| SPIRV-Cross | Shader reflection & transpilation | --with-spirv-cross |
| Vulkan SDK | Vulkan backend | --with-vulkan |
| FFmpeg | Video recording & streaming | --with-ffmpeg |
| Metal (macOS framework) | Metal backend | --with-metal |
| Direct3D 11 (Windows SDK) | Direct3D 11 backend | --with-d3d11 (Windows, on by default) |
| Direct3D 12 (Windows SDK) | Direct3D 12 backend | --with-d3d12 (Windows, on by default) |
Installation
Via PIE (PHP Installer for Extensions)
pie install phpolygon/php-vio
Pre-built Binaries
Download platform-specific binaries from the Releases page. Available for:
- Linux x86_64 / ARM64
- macOS x86_64 (Intel) / ARM64 (Apple Silicon)
- Windows x64
From Source (macOS)
brew install glfw glslang spirv-cross ffmpeg
phpize
./configure --enable-vio --with-glfw --with-glslang --with-spirv-cross \
--with-vulkan --with-ffmpeg --with-metal
make -j$(sysctl -n hw.ncpu)
sudo make install
From Source (Linux)
# Ubuntu/Debian sudo apt install php-dev libglfw3-dev glslang-dev libvulkan-dev \ libavcodec-dev libavformat-dev libavutil-dev libswscale-dev \ spirv-cross libspirv-cross-c-shared-dev phpize ./configure --enable-vio --with-glfw --with-glslang --with-spirv-cross \ --with-vulkan --with-ffmpeg make -j$(nproc) sudo make install
Windows
On Windows, no build toolchain is needed — PHP extensions are distributed as pre-compiled DLLs. Download the matching DLL from the Releases page (match your PHP version and thread-safety mode), then:
- Copy
php_vio.dllinto your PHPext\directory - Add
extension=vioto yourphp.ini - Restart PHP / your web server
All backends use conditional compilation (#ifdef HAVE_*), so builds without certain dependencies compile fine — those features are simply unavailable at runtime.
Quick Start
<?php // Create a window with OpenGL backend $ctx = vio_create("opengl", [ "width" => 800, "height" => 600, "title" => "Hello VIO", ]); while (!vio_should_close($ctx)) { vio_begin($ctx); vio_clear($ctx, 0.1, 0.1, 0.1); // 2D drawing vio_rect($ctx, 50, 50, 200, 100, ["color" => 0xFF0000FF]); vio_circle($ctx, 400, 300, 60, ["color" => 0x00FF00FF]); vio_draw_2d($ctx); vio_end($ctx); vio_poll_events($ctx); } vio_close($ctx); vio_destroy($ctx);
API Overview
71 functions across these categories:
| Category | Functions |
|---|---|
| Context | vio_create, vio_begin, vio_end, vio_clear, vio_close, vio_destroy |
| Input | vio_key_pressed, vio_mouse_position, vio_mouse_button, vio_on_key |
| 2D | vio_rect, vio_circle, vio_line, vio_sprite, vio_text, vio_draw_2d |
| 3D | vio_mesh, vio_shader, vio_pipeline, vio_bind_pipeline, vio_draw |
| Textures | vio_texture, vio_bind_texture, vio_texture_load_async |
| Fonts | vio_font, vio_text, vio_text_measure, vio_font_load_async |
| Buffers | vio_uniform_buffer, vio_update_buffer |
| Audio | vio_audio_load, vio_audio_play, vio_audio_pause, vio_audio_stop |
| Recording | vio_recorder, vio_recorder_capture, vio_recorder_stop |
| Streaming | vio_stream, vio_stream_push, vio_stream_stop |
| Headless | vio_read_pixels, vio_save_screenshot, vio_compare_images |
| Shaders | vio_shader_reflect, shader compilation via glslang |
| Plugins | vio_plugins, vio_plugin_info |
Full API documentation: see vio.stub.php
Backends
| Backend | Status | Platforms |
|---|---|---|
| Direct3D 12 | Stable | Windows only |
| Direct3D 11 | Stable | Windows only |
| Metal | Stable | macOS only |
| OpenGL 4.1 | Stable | macOS, Linux, Windows |
| Vulkan | Experimental | macOS (MoltenVK), Linux, Windows |
| Null | Stable | All (for unit testing) |
Backend auto-selection is platform-specific:
- Windows: Direct3D 12 → Direct3D 11 → Vulkan → OpenGL
- macOS: Metal → OpenGL (Vulkan via MoltenVK is opt-in, not auto)
- Linux: Vulkan → OpenGL
Null is never auto-selected; request it explicitly with vio_create("null") for headless tests. Override auto-selection per call (vio_create("d3d11")) or globally via the vio.default_backend INI setting.
Performance: Metal vs OpenGL
Benchmarked on Apple M2 Pro (macOS 26.4, 1280x720, VSync off). Measures draw + flush time only (excludes present/VSync wait).
| Scenario | Metal (median) | OpenGL (median) | Delta |
|---|---|---|---|
| 500 rects | 192 us | 179 us | +7% |
| 200 rects + 200 rounded rects + 50 text | 323 us | 313 us | +3% |
| 1000 rects + 100 text | 301 us | 374 us | -20% |
Tail latency (frame time consistency):
| Percentile | Metal | OpenGL |
|---|---|---|
| p95 | 306-601 us | 437-754 us |
| p99 | 375-674 us | 907-953 us |
Metal is slightly slower on simple scenes due to command encoding overhead, but 20% faster on heavy scenes (1000+ draw calls with text). More importantly, Metal delivers 30-40% better tail latency — fewer frame time spikes and more consistent rendering.
Testing
NO_INTERACTION=1 TEST_PHP_EXECUTABLE=$(which php) \ php run-tests.php -d extension=$PWD/modules/vio.so tests/
38 tests included, covering headless rendering, 2D/3D pipelines, shaders, audio, input, and visual regression testing.
License
phpolygon/php-vio 适用场景与选型建议
phpolygon/php-vio 是一款 基于 C 开发的 Composer 扩展包,目前已累计 25 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 04 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「audio」 「extension」 「video」 「Rendering」 「Gamedev」 「Vulkan」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 phpolygon/php-vio 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 phpolygon/php-vio 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 phpolygon/php-vio 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
A custom URL rule class for Yii 2 which allows to create translated URL rules
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
Library for manipulating audio files (validating, transcoding, and tagging)
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
UI Kit 3 Extension for Yii2
统计信息
- 总下载量: 25
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 37
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-11