Comments (10)
释放:$query->destruct();
如果是swoole:当work处理到了某个数量的时候重启work进程
from querylist.
自己在合适的位置,释放一下就行了
from querylist.
cli下自己释放了自己业务产生的变量,但循环执行一些任务的时候,依然会存在内存一直飙升的问题,看了下源码,没发现是哪儿的问题
from querylist.
- 可以贴贴demo,才好分析呀
from querylist.
for($i=188;$i<1800;$i++){
$tmpp = $i100;
$str = "$tmpp,100";
$res = $db -> query([""],"",$str,"");
foreach($res as $v){
$data = [];
$tmp = QueryList::get($v['url'])->encoding('UTF-8','GB2312');
$data['location'] = $tmp->find("#Label18")->text();
$data['num'] = $tmp ->find("#Label16")->text();
$data['date'] = $tmp ->find("#Label24")->text();
$data['price'] = $tmp ->find("#Label23")->text();
$data['company_b'] = $tmp ->find("#Label19")->text();
$data['company_a'] = $tmp ->find("#Label21")->text();
$data['type'] = $tmp ->find("#Label17")->text();
$data['area'] = $tmp ->find("#Label22")->text();
// $db-> update($data,'id='.$v['id']);
echo $v['id']."\r\n";
$tmp = null;
$data = null;
$v = null;
}
$tmpp = null;
$str = null;
$res = null;
echo 'page: '.$i."\r\n";
}
如上:我注释掉所有业务相关代码;
仅保留循环内的:
$tmp = QueryList::get($v['url'])->encoding('UTF-8','GB2312');
和:
$tmp = null;
这两句,打开任务管理器,依然看到cli的php进程没秒2M左右的不停增加,家里的电脑,在350M的时候会触发GC;公司的电脑,会一直+到1.5G内存耗费,然后退出cli,你可以随便找个翻页的网址测试下哈,不加任何业务代码,单纯的QueryList::get
,然后unset
掉,也没用,现在只能依靠系统的强制GC。
from querylist.
- 在本地运行了一下,内存使用确实一直在增长
public function test1()
{
$gUrl = 'http://www.badmintoncn.com/';
for($i=188;$i<1800;$i++){
$tmpp = ($i-1)*100;
$str = "$tmpp,100";
// $res = $db -> query([""],"",$str,"");
$res = [
'id'=>1,
'url'=>''
];
for($i=0;$i<100;$i++){
$data = [];
$tmp = QueryList::get($gUrl)->encoding('UTF-8','GB2312');
$data['location'] = $tmp->find("#Label18")->text();
$data['num'] = $tmp ->find("#Label16")->text();
$data['date'] = $tmp ->find("#Label24")->text();
$data['price'] = $tmp ->find("#Label23")->text();
$data['company_b'] = $tmp ->find("#Label19")->text();
$data['company_a'] = $tmp ->find("#Label21")->text();
$data['type'] = $tmp ->find("#Label17")->text();
$data['area'] = $tmp ->find("#Label22")->text();
$tmp = null;
$data = null;
}
$size = memory_get_usage();
echo $this->convert($size).PHP_EOL;
sleep(1);
$tmpp = null;
$str = null;
$res = null;
echo 'page: '.$i."\r\n";
}
}
public function convert($size)
{
$unit=array('b','kb','mb','gb','tb','pb');
return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
}
- 结果部分截图如下:
7.35 mb
page: 100
7.51 mb
page: 100
7.82 mb
page: 100
7.98 mb
page: 100
8.15 mb
page: 100
8.31 mb
page: 100
8.48 mb
page: 100
from querylist.
把这个问题解决了,搭配其他的任务投递方案,无人值守会更舒服,看好你这个框架哦,加油。持续跟进这个问题。
from querylist.
使用完QueryList对象后要及时调用 destruct()
方法释放内存占用。
from querylist.
全部是动态代理闭包未释放内存。
from querylist.
已优化内存占用
from querylist.
Related Issues (20)
- Add support laravel 9 HOT 5
- 啥时候能支持laravel9 HOT 1
- Fatal error: Uncaught TypeError: Argument 1 passed to QL\Services\MultiRequestService::QL\Services\{closure}() must be an instance of GuzzleHttp\Exception\RequestException, instance of GuzzleHttp\Exception\ConnectException given HOT 3
- 希望支持一下laravel9&&php8+ HOT 4
- 期望实现devtools-protocol,就能和puppeteer一样愉快的使用了 HOT 1
- 依赖库 pguardiario/phpuri 已被删除
- PHP7.4环境代码执行结果与预期不一致! HOT 3
- 使用【Baidu 插件】返回 百度安全验证 网络不给力,请稍后重试 返回首页 问题反馈 HOT 1
- 希望支持php8.0/laravel 9 HOT 2
- The domain querylist.cc is expired,please fix it
- 什么时候支持php8啊,已经在用8.2了,马上都出8.3了 HOT 4
- php8.1 fixes - Cannot push my branch
- QueryList4.2.8列表采集,不能正常执行 HOT 1
- 能否兼容 guzzlehttp/guzzle 升级 HOT 1
- 突然提示 Package tightenco/collect is abandoned, 能否升级一下呢? HOT 1
- thinkphp8框架 HOT 6
- 难道你们都没有这个致命错误? HOT 6
- 为什么经常有这种错误 HOT 2
- 版本依赖有问题 HOT 6
- laravel 9.19版本安装composer require jaeger/querylist 出现版本冲突 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from querylist.