SlideShare a Scribd company logo
 Fluentd	
PHP	
  &
@chobi_e
chobi_e	
  is:	
  
	
  
PECL	
  Sundown	
  Author	
                         (will	
  be	
  release	
  soon)	
  
h>ps://github.com/chobie/php-­‐sundown	
  


libgit2	
  PHP	
  Binding	
  Author	
  
h>ps://github.com/libgit2/php-­‐git	
  


phpredis	
  contributor                      	
  
h>ps://github.com/nicolasff/phpredis	
  
Scaling	
  web	
  servers.
Scaling	
  web	
  servers.	
  
basically,	
  just	
  add	
  web	
  server	
  to	
  the	
  array.
then,	
  how	
  about	
  collecLng	
  log	
  files?
using	
  log	
  file	
  
using	
  log	
  file	
  	
                            Are	
  you	
  serious?
using	
  syslog	
  like	
  middleware
using	
  syslog	
  like	
  middleware	
                                          Not	
  Bad.
using	
  reliable	
  and	
  distributed	
  log	
  collector:	
  	




Note:	
  fluent-­‐logger-­‐php	
  does	
  not	
  support	
  output	
  buffering.	
  So	
  local	
  fluentd	
  as	
  a	
  buffer	
  in	
  this	
  case.
using	
  reliable	
  and	
  distributed	
  log	
  collector:	
  	
                                                                         that’s	
  the	
  best	
  soluLon	
  IMHO	




Note:	
  fluent-­‐logger-­‐php	
  does	
  not	
  support	
  output	
  buffering.	
  So	
  local	
  fluentd	
  as	
  a	
  buffer	
  in	
  this	
  case.
fluentd	
  provides	
  robust	
  
messaging	
  soluLon
for	
  Data	
  Mining	
                          Data	
  Mining
for	
  queued	
  job	
                         Data	
  Mining	




                                Queued	
  job
fluentd	
  first	
  step	
  with	
  PHP
install	
  by	
  composer
Fluentd and PHP
#	
  composer.json	
  
{	
  
	
  	
  "name":	
  "my-­‐project",	
  
	
  	
  "version":	
  "1.0.0",	
  
	
  	
  "require":	
  {	
  
	
  	
  	
  	
  "fluent/logger":	
  "master-­‐dev"	
  
	
  	
  }	
  
}
wget	
  h>p://getcomposer.org/composer.phar	
  
php	
  -­‐d	
  detect_unicode=0	
  composer.phar	
  install
<?php	
  
require	
  "vendor/.composer/autoload.php";	
  
	
  
use	
  FluentLoggerFluentLogger;	
  
	
  
$logger	
  =	
  FluentLogger::open(	
  
	
  	
  	
  "debug.test",	
  
	
  	
  	
  "localhost",	
  
	
  	
  	
  "24224”	
  
);
install	
  by	
  copy	
  the	
  tree.
git	
  clone	
  h>ps://github.com/fluent/fluent-­‐logger-­‐php.git	
  
cp	
  -­‐r	
  src/Fluent	
  <path/to/your_project>
php	
  library	
  which	
  using	
  Fluentd.
MonologFluent	
  by	
  nrk	
  
h>ps://github.com/nrk/monolog-­‐fluent.git
what	
  is	
  Monolog?	
  
	
  
Monolog	
  by	
  Seldaek.	
  
h>ps://github.com/Seldaek/monolog	
  
	
  
	
  
Monolog	
  is:	
  
heavily	
  inspired	
  by	
  Python's	
  Logbook	
  library,	
  although	
  most	
  
concepts	
  have	
  been	
  adjusted	
  to	
  fit	
  to	
  the	
  PHP	
  world.	
  
	
  
install	
  
$	
  wget	
  h>p://getcomposer.org/composer.phar	
  
$	
  php	
  composer.phar	
  install	
  
	
  
<?php	
  
use	
  NrkFluentMonologFluentHandler;	
  
	
  
$log	
  =	
  new	
  MonologLogger('debug.monolog');	
  
	
  
$log-­‐>pushHandler(new	
  FluentHandler('h>p://127.0.0.1'));	
  
$log-­‐>pushHandler(new	
  FluentHandler('tcp://127.0.0.1'));	
  
	
  
$log-­‐>addError("OH	
  NOES!!11!1!");
introduce	
  my	
  fluent	
  plugin
fluent-­‐plugin-­‐delayed	
  
	
  -­‐	
  delayed	
  output	
  plugin.	
  	
  
h>ps://github.com/chobie/fluent-­‐plugin-­‐delayed	
  
fluent-­‐plugin-­‐delayed	
  
	
  -­‐	
  delayed	
  output	
  plugin.	
  	
  
h>ps://github.com/chobie/fluent-­‐plugin-­‐delayed	
  
                Client	
                     event{	
  
                     	
  Lme:	
  2011-­‐10-­‐22	
  10:00:05,	
  #	
  5	
  seconds	
  future	
  
                     	
  ...	
  
                     }	
  

           delayed	
  plugin	
                     :	
  aler	
  5	
  seconds.	
  then	
  delayed	
  plugin	
  outputs	
  
                     the	
  data	
  to	
  other	
  output	
  plugin.	
  

               output
other	
  Ideas.	
  
	
  
fluent-­‐plugin-­‐cooldown	
  
	
  -­‐	
  coolodowned	
  outputs	
  when	
  specified	
  key	
  received.	
  
	
  
fluent-­‐plugin-­‐sampler	
  
	
  -­‐	
  only	
  outputs	
  N	
  %	
  data.	
  
GitHQ	
  /	
  Kokuban	
  
Github	
  /	
  gist	
  clone	
  (sLll	
  under	
  development)
updaLng	
  ssh	
  key	
  	
  is	
  	
  pain	
  in	
  ass.	
/home/git/.ssh/authorized_keys
updaLng	
  SSH	
  Authorized	
  keys	
                                                                       only	
  pass	
  cooldowned	
  
                                                                                message.	




   send	
  public	
  key	
    client	
           web	
  server	
             fluentd	
          cooldown	
          exec	
                                 sending	
  message	
  via	
  fluentdLogger	

                                                     redis	
                                                                                  update	
  authorized_keys	
  	



                                                                  obtain	
  ssh	
  public	
  keys
Web	
  developer	
  only	
  knows	
  tag	
  for	
  queued	
  job.
Web	
  developer	
  only	
  knows	
  tag	
  for	
  queued	
  job.	
Server	
  engineer	
  only	
  implements	
  reliable	
  consumer	
  
plugin	
  for	
  Fluentd.
Sounds	
  good?
fluent-­‐logger-­‐php	
  status.
fluentd	
  protocol	
  support	
  ✔	
  
h>p	
  protocol	
  support	
  ✔	
  
composer	
  support	
  ✔	
  
PEAR	
  package	
  support	
  ✔	
  
-­‐	
  but	
  I	
  don’t	
  provide	
  pear	
  channel.	
  	
  

	
  
message	
  pack	
  support	
  
buffering	
  support	
  
-­‐	
  does	
  not	
  support	
  as	
  there’s	
  trouble	
  some	
  for	
  using	
  persistent	
  variables	
  for	
  buffer.	
  
	
  
That’s	
  all	
  
That’s	
  all	
  
i	
  need	
  more	
  developer!	
  please	
  feel	
  free	
  to	
  pull	
  req	
  me.	
  
	
  
h>ps://github.com/chobie	
  

More Related Content

Fluentd and PHP