diff --git a/src/CollectorConfig.php b/src/CollectorConfig.php index ff433ae..8f44e7f 100644 --- a/src/CollectorConfig.php +++ b/src/CollectorConfig.php @@ -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); diff --git a/src/FileConsumer.php b/src/FileConsumer.php index 1306c4e..0be7ede 100644 --- a/src/FileConsumer.php +++ b/src/FileConsumer.php @@ -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(); } @@ -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() diff --git a/test/FileTester.php b/test/FileTester.php new file mode 100644 index 0000000..e4a30fa --- /dev/null +++ b/test/FileTester.php @@ -0,0 +1,16 @@ + 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"]]); \ No newline at end of file diff --git a/test/HttpTester.php b/test/HttpTester.php new file mode 100644 index 0000000..c34b7c6 --- /dev/null +++ b/test/HttpTester.php @@ -0,0 +1,18 @@ + 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"]]); \ No newline at end of file