Browse Source

更新iot代码,添加内存泄露代码

dev
mike 4 years ago
parent
commit
c28404e3cd
  1. 160
      app/Commons/Log.php
  2. 2
      app/Service/v3/Implementations/IOTAliService.php
  3. 3
      composer.json
  4. 70
      composer.lock
  5. 1
      config/autoload/aliiot.php

160
app/Commons/Log.php

@ -29,90 +29,90 @@ class Log
public function event($labels=null,$datas){
co(function () use ($labels,$datas){
$client = $this->getClient();
$kv = [];
foreach ($datas as $key => $value) {
$kv[] = $key."=".$value;
}
$pushLabels = [];
$event_name = 'event_'.env('APP_ENV');
if(!empty($labels)) $pushLabels[$event_name] = $labels;
/*
* data format:
curl -v -H "Content-Type: application/json" -XPOST -s "http://39.96.12.39:3100/loki/api/v1/push" --data-raw \
'{"streams": [{ "stream": { "foo": "bar2" }, "values": [ [ "1596274538882028800", "fizzbuzz" ] ] }]}'
*/
$ts = $this->getMsecTime() . '000000';
$datas = implode("&",$kv);
$values = [[$ts,$datas]];
$app_name = env('APP_NAME').'_'.env('APP_ENV');
$pushLabels['app']= $app_name;
$pushDatas = [
'streams'=>[
[
'stream'=>$pushLabels,
'values'=>$values,
]
]
];
$client->post(
env('LOG_HOST','http://39.96.12.39:3100').'/loki/api/v1/push',
[
'headers'=>[
'Content-Type'=>'application/json'
],
'body' => json_encode($pushDatas)
]
);
//var_dump(json_encode($pushDatas) );
});
// co(function () use ($labels,$datas){
// $client = $this->getClient();
// $kv = [];
// foreach ($datas as $key => $value) {
// $kv[] = $key."=".$value;
// }
// $pushLabels = [];
// $event_name = 'event_'.env('APP_ENV');
// if(!empty($labels)) $pushLabels[$event_name] = $labels;
// /*
// * data format:
// curl -v -H "Content-Type: application/json" -XPOST -s "http://39.96.12.39:3100/loki/api/v1/push" --data-raw \
// '{"streams": [{ "stream": { "foo": "bar2" }, "values": [ [ "1596274538882028800", "fizzbuzz" ] ] }]}'
// */
// $ts = $this->getMsecTime() . '000000';
// $datas = implode("&",$kv);
// $values = [[$ts,$datas]];
// $app_name = env('APP_NAME').'_'.env('APP_ENV');
// $pushLabels['app']= $app_name;
// $pushDatas = [
// 'streams'=>[
// [
// 'stream'=>$pushLabels,
// 'values'=>$values,
// ]
// ]
// ];
// $client->post(
// env('LOG_HOST','http://39.96.12.39:3100').'/loki/api/v1/push',
// [
// 'headers'=>[
// 'Content-Type'=>'application/json'
// ],
// 'body' => json_encode($pushDatas)
// ]
// );
// //var_dump(json_encode($pushDatas) );
// });
}
public function eventInTask($labels=null,$datas){
$client = $this->getClient();
$kv = [];
foreach ($datas as $key => $value) {
$kv[] = $key."=".$value;
}
$pushLabels = [];
$event_name = 'event_'.env('APP_ENV');
if(!empty($labels)) $pushLabels[$event_name] = $labels;
/*
* data format:
curl -v -H "Content-Type: application/json" -XPOST -s "http://39.96.12.39:3100/loki/api/v1/push" --data-raw \
'{"streams": [{ "stream": { "foo": "bar2" }, "values": [ [ "1596274538882028800", "fizzbuzz" ] ] }]}'
*/
$ts = $this->getMsecTime() . '000000';
$datas = implode("&",$kv);
$values = [[$ts,$datas]];
$app_name = env('APP_NAME').'_'.env('APP_ENV');
$pushLabels['app']= $app_name;
$pushDatas = [
'streams'=>[
[
'stream'=>$pushLabels,
'values'=>$values,
]
]
];
$client->post(
env('LOG_HOST','http://39.96.12.39:3100').'/loki/api/v1/push',
[
'headers'=>[
'Content-Type'=>'application/json'
],
'body' => json_encode($pushDatas)
]
);
// $client = $this->getClient();
// $kv = [];
// foreach ($datas as $key => $value) {
// $kv[] = $key."=".$value;
// }
// $pushLabels = [];
// $event_name = 'event_'.env('APP_ENV');
// if(!empty($labels)) $pushLabels[$event_name] = $labels;
// /*
// * data format:
// curl -v -H "Content-Type: application/json" -XPOST -s "http://39.96.12.39:3100/loki/api/v1/push" --data-raw \
// '{"streams": [{ "stream": { "foo": "bar2" }, "values": [ [ "1596274538882028800", "fizzbuzz" ] ] }]}'
// */
// $ts = $this->getMsecTime() . '000000';
// $datas = implode("&",$kv);
// $values = [[$ts,$datas]];
// $app_name = env('APP_NAME').'_'.env('APP_ENV');
// $pushLabels['app']= $app_name;
// $pushDatas = [
// 'streams'=>[
// [
// 'stream'=>$pushLabels,
// 'values'=>$values,
// ]
// ]
// ];
// $client->post(
// env('LOG_HOST','http://39.96.12.39:3100').'/loki/api/v1/push',
// [
// 'headers'=>[
// 'Content-Type'=>'application/json'
// ],
// 'body' => json_encode($pushDatas)
// ]
// );
//var_dump(json_encode($pushDatas) );
}

2
app/Service/v3/Implementations/IOTAliService.php

@ -24,7 +24,6 @@ class IOTAliService implements IOTServiceInterface
AlibabaCloud::accessKeyClient(config('aliiot.key'), config('aliiot.secret'))
->regionId(config('aliiot.region'))
->asDefaultClient();
try {
AlibabaCloud::rpc()
->product('Iot')
@ -38,6 +37,7 @@ class IOTAliService implements IOTServiceInterface
'TopicFullName' => "/".config('aliiot.prod_key')."/".$device_name."/user/get",
'MessageContent' => base64_encode($msg),
'ProductKey' => config('aliiot.prod_key'),
'IotInstanceId'=> config('aliiot.inst_id'),
],
])
->request();

3
composer.json

@ -43,7 +43,8 @@
"hyperf/consul": "^2.0",
"alibabacloud/client": "^1.5",
"hashids/hashids": "^4.0",
"hyperf/crontab": "^2.0"
"hyperf/crontab": "^2.0",
"hyperf/swoole-tracker": "2.0"
},
"require-dev": {
"swoole/ide-helper": "^4.5",

70
composer.lock

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "7ab1eb814ce8a0d34cfec6c2c0725022",
"content-hash": "8b0c7e443a061d0a1b78cdb85db6d105",
"packages": [
{
"name": "adbario/php-dot-notation",
@ -3646,6 +3646,74 @@
},
"time": "2020-12-16T01:47:21+00:00"
},
{
"name": "hyperf/swoole-tracker",
"version": "v2.0.0",
"source": {
"type": "git",
"url": "https://github.com/hyperf/swoole-tracker.git",
"reference": "85af3c06333d01f1dd27957379f38d48d1871f08"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/hyperf/swoole-tracker/zipball/85af3c06333d01f1dd27957379f38d48d1871f08",
"reference": "85af3c06333d01f1dd27957379f38d48d1871f08",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"hyperf/contract": "~2.0.0",
"hyperf/utils": "~2.0.0",
"php": ">=7.2",
"psr/container": "^1.0",
"psr/http-server-middleware": "^1.0",
"psr/log": "^1.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.9",
"malukenho/docheader": "^0.1.6",
"mockery/mockery": "^1.0",
"phpunit/phpunit": "^7.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
},
"hyperf": {
"config": "Hyperf\\SwooleTracker\\ConfigProvider"
}
},
"autoload": {
"psr-4": {
"Hyperf\\SwooleTracker\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "A swoole tracker library for Hyperf.",
"homepage": "https://hyperf.io",
"keywords": [
"hyperf",
"php",
"swoole",
"swoole-tracker"
],
"support": {
"docs": "https://hyperf.wiki",
"issues": "https://github.com/hyperf/hyperf/issues",
"pull-request": "https://github.com/hyperf/hyperf/pulls",
"source": "https://github.com/hyperf/hyperf"
},
"time": "2020-06-19T13:11:07+00:00"
},
{
"name": "hyperf/task",
"version": "v2.0.18",

1
config/autoload/aliiot.php

@ -8,4 +8,5 @@ return [
'secret' => env('ALI_IOT_SECRET', ''),
'region' => env('ALI_IOT_REGION', ''),
'prod_key' => env('ALI_IOT_PRODUCT_KEY', ''),
'inst_id' => env('ALI_IOT_INST_ID', ''),
];
Loading…
Cancel
Save