承接 rgnu/libsystem-thread 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rgnu/libsystem-thread

Composer 安装命令:

composer require rgnu/libsystem-thread

包简介

System Threads manage for PHP

README 文档

README

System Thread fork and run code in sub-processes.

<?php
require_once __DIR__ . '/vendor/autoload.php';

class SleepThread extends System_Thread
{
	private $sleep;
	
	public function __construct($sleep=3) {
		$this->sleep = $sleep;
	}
	
	public function run() {
		while ($this->sleep && !$this->isTerminated()) {
		    print "Sleep:".$this->sleep."\n";
		    $this->sleep -= 1;
		    sleep(1);
		};
	}
}


class ThreadListener implements Event_Observer
{
	public function update(Event_Observed $obj)
	{
		printf("%s > %s activeCount=%d\n", strftime("%Y-%m-%d %H:%M:%S", time()), "$obj", $obj->activeCount());
	}
}

class System_Thread_ManagerStrategy_Constant extends System_Thread_ManagerStrategy
{
	public function __construct($number)
	{
		$this->number = $number;
	}
	
	public function manage(System_Thread_Manager $manager)
	{
		return $this->number;
	}
}


$l = new ThreadListener();

$t1 = new SleepThread(4);
$t1->attach($l);

$t2 = new SleepThread(2);
$t2->attach($l);

$g = new System_Thread_Group();
$g->addThread($t1);
$g->addThread($t2);
$g->attach($l);

$m1 = new System_Thread_Manager($t1, new System_Thread_ManagerStrategy_Constant(6));
$m1->attach($l);

$m2 = new System_Thread_Manager($t2, new System_Thread_ManagerStrategy_Constant(2));
$m2->attach($l);

$mg = new System_Thread_Group();
$mg->addThread($m1);
$mg->addThread($m2);
$mg->attach($l);

$th = $mg;

pcntl_signal(SIGTERM, array($th, 'stop'));
pcntl_signal(SIGINT,  array($th, 'stop'));

$th->start();

while($th->isAlive()) { 
	echo "Active Thread " . $th->activeCount() . "\n";
	sleep(1);
}

统计信息

  • 总下载量: 14
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-2.1
  • 更新时间: 2013-11-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固