mingfei/querylist-coroutine
Composer 安装命令:
composer require mingfei/querylist-coroutine
包简介
QueryList Plugin: 协程插件
README 文档
README
QueryList Plugin: Coroutine
Installation
composer require mingfei/querylist-coroutine
API
- Coroutine coroutine(int $size=0):use Coroutine QueryList.
class Coroutine:
- Coroutine size($size):set max parallel num.
- Coroutine add(string $option):add option.
- Coroutine success(callable $callable): success callback.
- Coroutine wait($post): wait for request.
Usage
- Bind Coroutine
use QL\QueryList; use QL\Ext\Coroutine; $ql = new QueryList(); $ql->use(Coroutine::class); //or Custom function name $ql->use(Coroutine::class,'coroutine');
- Your Rule like this
$rule = [ 'package' => ['.col-sm-9>h4>a','text'], 'link' => ['.col-sm-9>h4>a','href'], 'desc'=>['.col-sm-9>p:last','text'], 'language'=>['.col-sm-9>p:eq(0)','text'], 'star'=>['.col-sm-3 span:eq(1)','text'], ]; $range = "li .row";
- Use Coroutine
$coroutine = $ql->range($range)->rules($rule)->coroutine(); $coroutine->add("https://packagist.org/explore/popular"); $data = $coroutine->wait(); print_r($data->all());
- Use Coroutine with success callback
$coroutine = $ql->range($range)->rules($rule)->coroutine(); $coroutine->add("https://packagist.org/explore/popular"); $coroutine->success(function($item){ $item["star"] = preg_replace('/\D/s', '', $item["star"] ); return $item; }); $data = $coroutine->wait(); print_r($data->all());
Out:
Array
(
[0] => Array
(
[package] => symfony/polyfill-mbstring
[link] => /packages/symfony/polyfill-mbstring
[desc] => Symfony polyfill for the Mbstring extension
[language] => PHP
[star] => 7373
)
[1] => Array
(
[package] => psr/log
[link] => /packages/psr/log
[desc] => Common interface for logging libraries
[language] => PHP
[star] => 9976
)
...
)
- Use Coroutine with size
$coroutine = $ql->range($range)->rules($rule)->coroutine(1000); $range = range(1,10000); foreach($range as $i){ $coroutine->add("https://packagist.org/explore/popular?page=".$i); } $data = $coroutine->wait(); print_r($data->all()); //爬取速度受packagist.org并发限制,这里大约需要等几分钟
Out:
use 424.99214887619s
mingfei/querylist-coroutine 适用场景与选型建议
mingfei/querylist-coroutine 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 03 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 mingfei/querylist-coroutine 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mingfei/querylist-coroutine 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-03-01