enzolarosa / php_multithread
此软件包最新版本(0.15)没有提供许可信息。
PHP多线程处理库
0.15
2017-08-29 03:34 UTC
Requires
- php: >=5.3.0
README
enzolarosa - vincenzo@ctlr.it
文档和下载
最新版本可在github上获取: - http://github.com/enzolarosa/PHP-Multithread/
许可
本代码在GNU LGPL许可下发布
请勿更改文件头。
这是一个自由软件库;您可以在自由软件基金会发布的GNU Lesser General Public License的条款下重新分发和/或修改它;许可证的第2版,或(根据您的选择)任何更高版本。
本库的发布是希望它有用,但没有任何保证;甚至没有关于其适销性或特定用途的暗示保证。
有关详细信息,请参阅GNU Lesser General Public License。
描述
此库提供了一个轻量级/简单的面向对象的PHP类,用于处理多线程。请检查示例文件夹以获取如何使用它的示例。此库需要安装pcntl(《https://php.ac.cn/pcntl》扩展)并仅适用于Unix发行版。
设置
您可以使用composer使用此库。
{
"require": {
"enzolarosa/php_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