Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 4 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Commits on Apr 11, 2012
@chobie chobie correct travis biuld status url [skip-ci] 76501b3
@chobie chobie now, FluentLogger will connect every request as persistent socket is …
…little bit experimental.

[Changes]
* persistent mode is getting experimental. now FluentLogger will connect to fluentd every request.
  Probably, fluentd supports unix domain socket officially soon. then we'll adopt that.
* usleep strategy becomes default backoff strategy.
  In almost cases, all web applcication will get slowly if fluentd downs long time.

Thanks, guys
b3b4b88
@chobie chobie Merge branch 'develop' 25cf307
@chobie chobie bmuped up to v0.3.6 07df674
Showing with 47 additions and 22 deletions.
  1. +4 −4 README.md
  2. +43 −18 src/Fluent/Logger/FluentLogger.php
View
8 README.md
@@ -2,13 +2,13 @@
**fluent-logger-php** is a PHP library to record events to fluentd from a PHP application.
-[![Build Status](https://secure.travis-ci.org/chobie/fluent-logger-php.png)](http://travis-ci.org/chobie/fluent-logger-php)
+[![Build Status](https://secure.travis-ci.org/fluent/fluent-logger-php.png)](http://travis-ci.org/fluent/fluent-logger-php)
## API Document
-current version: v0.3.5
+current version: v0.3.6
-- http://fluent.github.com/fluent-logger-php/v0.3.5
+- http://fluent.github.com/fluent-logger-php/v0.3.6
- http://fluent.github.com/fluent-logger-php/v0.3.3
- http://fluent.github.com/fluent-logger-php/v0.3.2
- http://fluent.github.com/fluent-logger-php/v0.3.1
@@ -46,7 +46,7 @@ composer.json
"name": "my-project",
"version": "1.0.0",
"require": {
- "fluent/logger": "v0.3.5"
+ "fluent/logger": "v0.3.6"
}
}
````
View
61 src/Fluent/Logger/FluentLogger.php
@@ -34,10 +34,10 @@ class FluentLogger extends BaseLogger
/* Fluent uses port 24224 as a default port */
const DEFAULT_LISTEN_PORT = 24224;
- const DEFAULT_ADDRESS = "127.0.0.1";
+ const DEFAULT_ADDRESS = "127.0.0.1";
/**
- * backoff strategies: default exponentail
+ * backoff strategies: default usleep
*
* attempts | wait
* 1 | 0.003 sec
@@ -58,6 +58,7 @@ class FluentLogger extends BaseLogger
/* @var string Various style transport: `tcp://localhost:port` */
protected $transport;
+ /* @var resource */
protected $socket;
/* @var PackerInterface */
@@ -66,9 +67,10 @@ class FluentLogger extends BaseLogger
protected $options = array(
"socket_timeout" => self::SOCKET_TIMEOUT,
"connection_timeout" => self::CONNECTION_TIMEOUT,
- "backoff_mode" => self::BACKOFF_TYPE_EXPONENTIAL,
+ "backoff_mode" => self::BACKOFF_TYPE_USLEEP,
"backoff_base" => 3,
"usleep_wait" => self::USLEEP_WAIT,
+ "persistent" => false,
);
protected static $supported_transports = array(
@@ -82,6 +84,7 @@ class FluentLogger extends BaseLogger
"backoff_mode",
"backoff_base",
"usleep_wait",
+ "persistent",
);
protected static $instances = array();
@@ -235,6 +238,8 @@ public static function open($host = FluentLogger::DEFAULT_ADDRESS, $port = Fluen
/**
* clear fluent-logger instances from static variable.
*
+ * this useful when testing.
+ *
* @return void
*/
public static function clearInstances()
@@ -252,11 +257,16 @@ public static function clearInstances()
*/
protected function connect()
{
+ $connect_options = \STREAM_CLIENT_CONNECT;
+ if ($this->getOption("persistent", false)) {
+ $connect_options |= \STREAM_CLIENT_PERSISTENT;
+ }
+
// could not suppress warning without ini setting.
// for now, we use error control operators.
$socket = @stream_socket_client($this->transport,$errno,$errstr,
$this->getOption("connection_timeout",self::CONNECTION_TIMEOUT),
- \STREAM_CLIENT_CONNECT | \STREAM_CLIENT_PERSISTENT
+ $connect_options
);
if (!$socket) {
@@ -307,6 +317,13 @@ public function post2(Entity $entity)
return $this->postImpl($entity);
}
+ /**
+ * post implementation
+ *
+ * @param \Fluent\Logger\Entity $entity
+ * @return bool
+ * @throws \Exception
+ */
protected function postImpl(Entity $entity)
{
$buffer = $packed = $this->packer->pack($entity);
@@ -349,13 +366,12 @@ protected function postImpl(Entity $entity)
}
}
- $retry++;
-
if ($this->getOption('backoff_mode',self::BACKOFF_TYPE_EXPONENTIAL) == self::BACKOFF_TYPE_EXPONENTIAL) {
- usleep(pow($this->getOption("backoff_base",3), $retry)*1000);
+ $this->backoffExponential(3, $retry);
} else {
usleep($this->getOption("usleep_wait",self::USLEEP_WAIT));
}
+ $retry++;
continue;
}
@@ -371,6 +387,18 @@ protected function postImpl(Entity $entity)
}
/**
+ * backoff exponential sleep
+ *
+ * @param $base int
+ * @param $attempt int
+ */
+ public function backoffExponential($base, $attempt)
+ {
+ usleep(pow($base, $attempt)*1000);
+ }
+
+
+ /**
* write data
*
* @param string $data
@@ -382,30 +410,27 @@ protected function write($buffer)
}
/**
- * close socket
+ * close the socket
*
* @return void
*/
public function close()
{
- /**
- * persistent socket should not close.
- * but it should close manualy when it had some error (e.g Breaking Pipe...)
- */
if (is_resource($this->socket)) {
fclose($this->socket);
}
}
+ /**
+ * destruct objects and socket.
+ *
+ * @return void
+ */
public function __destruct()
{
- /* do not close socket as we use persistent connection */
-
- /* it should flush every request but sometimes this makes socket error. hmm.
- if (is_resource($this->socket)) {
- fflush($this->socket);
+ if ($this->getOption("persistent")) {
+ fclose($this->socket);
}
- */
}
/**

No commit comments for this range

Something went wrong with that request. Please try again.