>백엔드 개발 >PHP 튜토리얼 >PHP 스레드 라이브러리: pthreads

PHP 스레드 라이브러리: pthreads

WBOY
WBOY원래의
2016-07-25 09:12:301229검색

该项目为 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.

示例代码:

  1. class AsyncOperation extends Thread {
  2. public function __construct($arg){
  3. $this->arg = $arg;
  4. }
  5. public function run(){
  6. if($this->arg){
  7. printf("Hello %sn", $this->arg);
  8. }
  9. }
  10. }
  11. $thread = new AsyncOperation("World");
  12. if($thread->start())
  13. $thread->join();
  14. ?>
复制代码

项目主页:http://www.open-open.com/lib/view/home/1391824675848



성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.