alfallouji / php_multithread
此软件包最新版本(0.1.4)没有可用的许可证信息。
用于处理多线程的iPHP库
0.1.4
2015-04-03 03:49 UTC
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-09-14 16:08:27 UTC
README
Al-Fallouji Bashar - bashar@alfallouji.com
文档和下载
最新版本可在github上找到:- http://github.com/alfallouji/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": {
"alfallouji/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