Skip to content

Commit

Permalink
[bugfix]修复文件读写bug
Browse files Browse the repository at this point in the history
  • Loading branch information
hTangle committed Dec 8, 2020
1 parent 948b675 commit 6fa5db1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/CollectorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static function init_datarangers_collector($config)
self::setSAVE(false);
self::setSEND(true);
}
if (in_array("domain", $config)) {
if (array_key_exists("domain", $config)) {
self::setURL($config["domain"] . Constants::$APP_LOG_URL);
} else if (self::isSend()) {
throw new RangersSDKException(Constants::$DOMAIN_EXCPETION);
Expand Down
5 changes: 3 additions & 2 deletions src/FileConsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public function __construct()
if ($this->currentIndex != 0) $this->currentIndex++;
$this->fullTarget = $this->targetPrefix . $this->targetName . ".log";
$this->currentName = $this->targetName . "." . date("Y.m.d.H", time());
echo $this->currentIndex, $this->targetPrefix, " ", $this->targetName, " ", $this->fullTarget;
$this->output = fopen($this->fullTarget, "a+");
$this->changeOutputStream();
}
Expand Down Expand Up @@ -103,7 +102,9 @@ public function send($msg)
public function close()
{
if ($this->output == null) return true;
return fclose($this->output);
if(is_resource($this->output))
return fclose($this->output);
return true;
}

function __destruct()
Expand Down
16 changes: 16 additions & 0 deletions test/FileTester.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
require '../vendor/autoload.php';

use DataRangers\AppEventCollector;
use DataRangers\CollectorConfig;
use DataRangers\FileConsumer;

CollectorConfig::init_datarangers_collector([
"save" => true,
"logger_file_prefix" => "sdk/log/",
"logger_file_name" => "datarangers.log",
"log_max_bytes" => 1024 * 10
]);
$rc = new AppEventCollector(new FileConsumer());
$rc->sendEvent("uuid16981", 10000002, null, ["__profile_set", "php_event"],
[["php_name" => "php", "php_version" => "5.6"], ["php_name" => "php", "php_version" => "5.6"]]);
18 changes: 18 additions & 0 deletions test/HttpTester.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

require '../vendor/autoload.php';
use DataRangers\AppEventCollector;
use DataRangers\CollectorConfig;
use DataRangers\HttpConsumer;

CollectorConfig::init_datarangers_collector([
"domain" => getenv("HTTP_DOMAIN"),
"send" => true,
"headers" => [
"Host" => getenv("HTTP_HOST"),
"Content-Type" => "application/json"
]
]);
$rc = new AppEventCollector(new HttpConsumer());
$rc->sendEvent("uuid16981", 10000002, null, ["__profile_set", "php_event"],
[["php_name" => "php", "php_version" => "5.6"], ["php_name" => "php", "php_version" => "5.6"]]);

0 comments on commit 6fa5db1

Please sign in to comment.