PHP的線程庫:pthreads
該項目為 PHP 提供基于 POSIX 的多線程編程機制。可異步執行任何與定義的用戶自定義方法和函數。內建支持同步和同步方法。
亮點
- 一個易于使用,快速學習的 Threading API for PHP5.3+
- Execute any and all predefined and user declared methods and functions asynchronously
- Ready made synchronization included, geared towards the PHP environment
- Seamless operation in multi-threaded SAPI environments
- A world of possibilities ...
技術特性
- Posix Threads
- Synchronization
- Worker Threads
- Synchronized Methods
- Complete Support for OO - ie. traits, interfaces, inheritance
- Full read/write/execute support for threaded objects
- Mutex ( direct, subset )
- Conditions ( direct, subset )
pthreads was written with simplicity, compatibility and efficiency in mind, it's performance beggars belief !!
環境要求
- PHP5.3+
- ZTS Enabled ( Thread Safety )
- Posix Threads Implementation
Testing has been carried out on x86, x64 and ARM, in general you just need a compiler and pthread.h
PHP 版本支持
pthreads should compile and work in any version of PHP from 5.3.0 to the latest release.
示例代碼:
<?php class AsyncOperation extends Thread { public function __construct($arg){ $this->arg = $arg; } public function run(){ if($this->arg){ printf("Hello %s\n", $this->arg); } } } $thread = new AsyncOperation("World"); if($thread->start()) $thread->join(); ?>
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!