godfery/ php_multithread
此包的最新版本(0.01)没有可用的许可信息。
用于处理多线程的iPHP库
0.01
2017-08-29 06:06 UTC
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-09-29 05:01:06 UTC
README
godfery - god.521@hotmail.com
文档和下载
此软件在github上的引用: - http://github.com/alfallouji/PHP-Multithread/
描述
此库提供了一个轻量级/简单的PHP面向对象类来处理多线程。请查看示例文件夹以获取如何使用它的示例。此库需要安装pcntl (https://php.ac.cn/pcntl) 扩展,并且它只能与Unix发行版一起使用。
设置
您可以使用composer使用此库。
{
"require": {
"godfery/multithread": "*"
}
}
用法
此客户端不依赖于任何框架,应该很容易与您自己的代码集成。您可以使用composer或您自己的自定义自动加载器。
示例文件夹包含了如何使用此库的示例。
示例
多线程简单任务
require(__DIR__ . '/../vendor/autoload.php');
$maxThreads = 5;
echo 'Example of the multi-thread manager with ' . $maxThreads . ' threads' . PHP_EOL . PHP_EOL;
$params = array();
$exampleTask = new Threading\Task\Example($params);
$multithreadManager = new Threading\Multiple();
$cpt = 0;
while (++$cpt <= 30)
{
$multithreadManager->start($exampleTask);
}
将提供以下输出
Example of the multi-thread manager with 5 threads
[Pid:23447] Task executed at 2015-04-03 14:49:18
[Pid:23448] Task executed at 2015-04-03 14:49:18
[Pid:23449] Task executed at 2015-04-03 14:49:18
[Pid:23450] Task executed at 2015-04-03 14:49:18
[Pid:23451] Task executed at 2015-04-03 14:49:18
[Pid:23452] Task executed at 2015-04-03 14:49:19
[Pid:23454] Task executed at 2015-04-03 14:49:19
[Pid:23453] Task executed at 2015-04-03 14:49:19
[Pid:23455] Task executed at 2015-04-03 14:49:19
[Pid:23456] Task executed at 2015-04-03 14:49:19
[Pid:23457] Task executed at 2015-04-03 14:49:20
[Pid:23458] Task executed at 2015-04-03 14:49:20
[Pid:23459] Task executed at 2015-04-03 14:49:20
[Pid:23460] Task executed at 2015-04-03 14:49:20
[Pid:23461] Task executed at 2015-04-03 14:49:20
[Pid:23463] Task executed at 2015-04-03 14:49:21
[Pid:23462] Task executed at 2015-04-03 14:49:21
[Pid:23464] Task executed at 2015-04-03 14:49:21
[Pid:23465] Task executed at 2015-04-03 14:49:21
[Pid:23466] Task executed at 2015-04-03 14:49:21
[Pid:23467] Task executed at 2015-04-03 14:49:22
[Pid:23468] Task executed at 2015-04-03 14:49:22
[Pid:23470] Task executed at 2015-04-03 14:49:22
[Pid:23469] Task executed at 2015-04-03 14:49:22
[Pid:23471] Task executed at 2015-04-03 14:49:22
[Pid:23472] Task executed at 2015-04-03 14:49:23
[Pid:23473] Task executed at 2015-04-03 14:49:23
[Pid:23474] Task executed at 2015-04-03 14:49:23
[Pid:23475] Task executed at 2015-04-03 14:49:23
[Pid:23476] Task executed at 2015-04-03 14:49:23