SlideShare une entreprise Scribd logo
1  sur  34
1

DAEMONS IN PHP
Zoltán Németh
Core Systems Manager @ Ustream
We. Are.
NOW PLAYING

DAEMONS IN PHP

1

Mar 26, 2013

.
CONTENTS







NOW PLAYING

WHY????
The core: daemonizing
Signal handling
Init scripts
Easy building of daemons
The current package
Open sourcing

DAEMONS IN PHP

2

Mar 26, 2013
WHY????
 The need for daemons
– Frequently running scheduled tasks
– Async processing
– Cron drawbacks:
 Can do only minute level
 Does not guarantee exact timing
 Cron jobs cannot be monitored
NOW PLAYING

DAEMONS IN PHP

3

Mar 26, 2013
WHY????
 PHP had some problems in the early days
– Hard to manage long running scripts
– Memory leaks
– Problems with forking
– Handling code changes

NOW PLAYING

DAEMONS IN PHP

4

Mar 26, 2013
WHY????
 Why daemons in PHP?
– Mostly PHP codebase
– Duplication of business logic leads to hell
 Lot of the logic codes used in daemons were
already used on the site

– PHP experience
– Quick and easy development
NOW PLAYING

DAEMONS IN PHP

5

Mar 26, 2013
DAEMONIZING – THE CONCEPT
 At startup, fork a child and exit from the
parent
– Start a new background session for the child

 In the child, have a loop which does the task
 Calculate timing after each loop and use
usleep for precision
 Have a pidfile (for monit etc)
NOW PLAYING

DAEMONS IN PHP

6

Mar 26, 2013
DAEMONIZING – THE CODE

NOW PLAYING

DAEMONS IN PHP

7

Mar 26, 2013
DAEMONIZING – THE CODE

NOW PLAYING

DAEMONS IN PHP

8

Mar 26, 2013
DAEMONIZING – THE CODE

NOW PLAYING

DAEMONS IN PHP

9

Mar 26, 2013
THE MAIN LOOP

NOW PLAYING

DAEMONS IN PHP

10

Mar 26, 2013
TIMING

NOW PLAYING

DAEMONS IN PHP

11

Mar 26, 2013
MEMORY LEAK CHECKING

NOW PLAYING

DAEMONS IN PHP

12

Mar 26, 2013
SIGNAL HANDLING
 Before PHP 5.3
– declare(ticks=1);
– Signal dispatch by php system, at every tick
– Unreliable
– Precise, fixed intervals

 Handler functions with pcntl_signal
NOW PLAYING

DAEMONS IN PHP

13

Mar 26, 2013
SIGNAL HANDLING
 PHP 5.3
– declare(ticks=1); is deprecated
– Signal dispatch by code:
pcntl_signal_dispatch
– More reliable
– Not precise, changing intervals (code
execution determines timing)
NOW PLAYING

DAEMONS IN PHP

14

Mar 26, 2013
SIGNAL HANDLING

NOW PLAYING

DAEMONS IN PHP

15

Mar 26, 2013
SIGNAL HANDLING

NOW PLAYING

DAEMONS IN PHP

16

Mar 26, 2013
INIT SCRIPTS
 Needed for monit, run daemons on startup,
etc
 In the beginning: separate init script for every
daemon
 Lot of copy-paste with minimal changing
information
 Hard to keep consistent: changes do not
propagate
NOW PLAYING

DAEMONS IN PHP

17

Mar 26, 2013
INIT SCRIPTS

NOW PLAYING

DAEMONS IN PHP

18

Mar 26, 2013
INIT SCRIPTS
 Conclusion: let’s have a common script in
the repo
 Take the name of the daemon as a
parameter
 Required: a class to run a daemon by its
name
– Daemon_Runner
NOW PLAYING

DAEMONS IN PHP

19

Mar 26, 2013
DAEMON RUNNER AND BUILDER
 Original setup: one php file for each daemon
 Each has its own class definition
– All variable initializations
– All configurations

 Constructing the object and all dependencies
 Starting the daemon
 Lot of boilerplate code  Daemon_Runner
NOW PLAYING

DAEMONS IN PHP

20

Mar 26, 2013
THE BOILERPLATE

NOW PLAYING

DAEMONS IN PHP

21

Mar 26, 2013
DAEMON RUNNER AND BUILDER
 Concept: a generic Runner class to run a
daemon based with a given task
 Task: the repeatedly running part of the
daemon
 Ustream_Daemon_Task interface
 Independent of the daemon configuration
NOW PLAYING

DAEMONS IN PHP

22

Mar 26, 2013
DAEMON RUNNER AND BUILDER
 Builder: a factory which creates the daemon
object
 All configuration options are handed over by
the builder
 Runner: call the builder and then run the
resulting class
 Configuration in .ini files
NOW PLAYING

DAEMONS IN PHP

23

Mar 26, 2013
INI FILE EXAMPLE

NOW PLAYING

DAEMONS IN PHP

24

Mar 26, 2013
BUILDER CALL, LIST OF OPTIONS

NOW PLAYING

DAEMONS IN PHP

25

Mar 26, 2013
BUILDER CODE

NOW PLAYING

DAEMONS IN PHP

26

Mar 26, 2013
AVAILABLE OPTIONS
 Sleep: period length (running time is
substracted)
 Minimum sleep: if running time is too long
 Factory: Task factory class
 Instance: for multi instance daemons
NOW PLAYING

DAEMONS IN PHP

27

Mar 26, 2013
THE PACKAGE





Ustream_Daemon_Daemon
Ustream_Daemon_Builder
Ustream_Daemon_Runner
Ustream_Daemon_PreconfiguredTaskDelegator: a
generic daemon class used by the builder. Runs a
task
 Ustream_Daemon_Logger: a file based logger for
the daemon package. Should be PSR3
NOW PLAYING

DAEMONS IN PHP

28

Mar 26, 2013
THE PACKAGE - INTERFACES
 Ustream_Daemon_Task
– doTask()

 Ustream_Daemon_TaskFactory
– createTaskFor(Ustream_Daemon_Daemon
$daemon)

 Ustream_Daemon_Starter
– start()
NOW PLAYING

DAEMONS IN PHP

29

Mar 26, 2013
THE DAEMON MONITOR







Centralized status monitor system
Every daemon reports status on UDP
Server in node.js
Displays info
Sends commands: e.g. Stop
Will be moved to a separate package

NOW PLAYING

DAEMONS IN PHP

30

Mar 26, 2013
THE DAEMON MONITOR

NOW PLAYING

DAEMONS IN PHP

31

Mar 26, 2013
OPEN SOURCING
 On github: https://github.com/ustream
 Some prerequisites:
– Remove remaining Ustream codebase
specific references
– Move Daemon Monitor related stuff to
separate package

 Planned ETA in April
NOW PLAYING

DAEMONS IN PHP

32

Mar 26, 2013
FURTHER PLANS
 Debug mode:
– remotely enabled
– collect output and dump when stopped

 Runtime setting of loglevel
– Possibly from remote daemon monitor

 Code coverage collecting
NOW PLAYING

DAEMONS IN PHP

33

Mar 26, 2013
34

QUESTIONS?

We. Are.
NOW PLAYING

DAEMONS IN PHP

34

Mar 26, 2013

.

Contenu connexe

Tendances

How to shut down Netapp san 9.2 cluster mode version1
How to shut down Netapp san 9.2 cluster mode version1How to shut down Netapp san 9.2 cluster mode version1
How to shut down Netapp san 9.2 cluster mode version1Saroj Sahu
 
Kernel Recipes 2016 - Understanding a Real-Time System (more than just a kernel)
Kernel Recipes 2016 - Understanding a Real-Time System (more than just a kernel)Kernel Recipes 2016 - Understanding a Real-Time System (more than just a kernel)
Kernel Recipes 2016 - Understanding a Real-Time System (more than just a kernel)Anne Nicolas
 
How to Shutdown Netapp Cluster Mode Storage System with Multi-Node Cluster (6...
How to Shutdown Netapp Cluster Mode Storage System with Multi-Node Cluster (6...How to Shutdown Netapp Cluster Mode Storage System with Multi-Node Cluster (6...
How to Shutdown Netapp Cluster Mode Storage System with Multi-Node Cluster (6...Saroj Sahu
 
How to shutdown the Netapp SAN 8.3 and 9.2 version
How to shutdown the Netapp SAN 8.3 and 9.2 versionHow to shutdown the Netapp SAN 8.3 and 9.2 version
How to shutdown the Netapp SAN 8.3 and 9.2 versionSaroj Sahu
 
Linux kernel debugging
Linux kernel debuggingLinux kernel debugging
Linux kernel debuggingHao-Ran Liu
 
Kernel Recipes 2016 - entry_*.S: A carefree stroll through kernel entry code
Kernel Recipes 2016 - entry_*.S: A carefree stroll through kernel entry codeKernel Recipes 2016 - entry_*.S: A carefree stroll through kernel entry code
Kernel Recipes 2016 - entry_*.S: A carefree stroll through kernel entry codeAnne Nicolas
 
Installation of ubuntu, ns3 and compiling first
Installation of ubuntu, ns3 and compiling firstInstallation of ubuntu, ns3 and compiling first
Installation of ubuntu, ns3 and compiling firstJawad Khan
 
How to assign unowned disk in the netapp cluster 8.3
How to assign unowned disk in the netapp cluster 8.3 How to assign unowned disk in the netapp cluster 8.3
How to assign unowned disk in the netapp cluster 8.3 Saroj Sahu
 
How to enable efficiency (deduplication and compression in netapp cluster mod...
How to enable efficiency (deduplication and compression in netapp cluster mod...How to enable efficiency (deduplication and compression in netapp cluster mod...
How to enable efficiency (deduplication and compression in netapp cluster mod...Saroj Sahu
 
Gabriele Santomaggio - Inside Elixir/Erlang - Codemotion Milan 2018
Gabriele Santomaggio - Inside Elixir/Erlang - Codemotion Milan 2018Gabriele Santomaggio - Inside Elixir/Erlang - Codemotion Milan 2018
Gabriele Santomaggio - Inside Elixir/Erlang - Codemotion Milan 2018Codemotion
 
How to install-gammu
How to install-gammuHow to install-gammu
How to install-gammusondaya
 
Composer Tutorial (PHP Hampshire Sept 2013)
Composer Tutorial (PHP Hampshire Sept 2013)Composer Tutorial (PHP Hampshire Sept 2013)
Composer Tutorial (PHP Hampshire Sept 2013)James Titcumb
 
Kannel configuration step by step with Motorolla Razer
Kannel configuration step by step with Motorolla RazerKannel configuration step by step with Motorolla Razer
Kannel configuration step by step with Motorolla RazerMahtab Rasheed
 
Help, my computer is sluggish
Help, my computer is sluggishHelp, my computer is sluggish
Help, my computer is sluggishKevin OBrien
 
The Shell Game Part 4: Bash Shortcuts
The Shell Game Part 4: Bash ShortcutsThe Shell Game Part 4: Bash Shortcuts
The Shell Game Part 4: Bash ShortcutsKevin OBrien
 
QEMU Sandboxing for dummies
QEMU Sandboxing for dummiesQEMU Sandboxing for dummies
QEMU Sandboxing for dummiesEduardo Otubo
 
3PAR: HOW TO CHANGE THE IP ADDRESS OF HP 3PAR SAN
3PAR: HOW TO CHANGE THE IP ADDRESS OF HP 3PAR SAN3PAR: HOW TO CHANGE THE IP ADDRESS OF HP 3PAR SAN
3PAR: HOW TO CHANGE THE IP ADDRESS OF HP 3PAR SANSaroj Sahu
 

Tendances (20)

F.a.q
F.a.qF.a.q
F.a.q
 
How to shut down Netapp san 9.2 cluster mode version1
How to shut down Netapp san 9.2 cluster mode version1How to shut down Netapp san 9.2 cluster mode version1
How to shut down Netapp san 9.2 cluster mode version1
 
Kernel Recipes 2016 - Understanding a Real-Time System (more than just a kernel)
Kernel Recipes 2016 - Understanding a Real-Time System (more than just a kernel)Kernel Recipes 2016 - Understanding a Real-Time System (more than just a kernel)
Kernel Recipes 2016 - Understanding a Real-Time System (more than just a kernel)
 
F.A.Q
F.A.QF.A.Q
F.A.Q
 
How to Shutdown Netapp Cluster Mode Storage System with Multi-Node Cluster (6...
How to Shutdown Netapp Cluster Mode Storage System with Multi-Node Cluster (6...How to Shutdown Netapp Cluster Mode Storage System with Multi-Node Cluster (6...
How to Shutdown Netapp Cluster Mode Storage System with Multi-Node Cluster (6...
 
How to shutdown the Netapp SAN 8.3 and 9.2 version
How to shutdown the Netapp SAN 8.3 and 9.2 versionHow to shutdown the Netapp SAN 8.3 and 9.2 version
How to shutdown the Netapp SAN 8.3 and 9.2 version
 
Linux kernel debugging
Linux kernel debuggingLinux kernel debugging
Linux kernel debugging
 
Kernel Recipes 2016 - entry_*.S: A carefree stroll through kernel entry code
Kernel Recipes 2016 - entry_*.S: A carefree stroll through kernel entry codeKernel Recipes 2016 - entry_*.S: A carefree stroll through kernel entry code
Kernel Recipes 2016 - entry_*.S: A carefree stroll through kernel entry code
 
Installation of ubuntu, ns3 and compiling first
Installation of ubuntu, ns3 and compiling firstInstallation of ubuntu, ns3 and compiling first
Installation of ubuntu, ns3 and compiling first
 
How to assign unowned disk in the netapp cluster 8.3
How to assign unowned disk in the netapp cluster 8.3 How to assign unowned disk in the netapp cluster 8.3
How to assign unowned disk in the netapp cluster 8.3
 
How to enable efficiency (deduplication and compression in netapp cluster mod...
How to enable efficiency (deduplication and compression in netapp cluster mod...How to enable efficiency (deduplication and compression in netapp cluster mod...
How to enable efficiency (deduplication and compression in netapp cluster mod...
 
Gabriele Santomaggio - Inside Elixir/Erlang - Codemotion Milan 2018
Gabriele Santomaggio - Inside Elixir/Erlang - Codemotion Milan 2018Gabriele Santomaggio - Inside Elixir/Erlang - Codemotion Milan 2018
Gabriele Santomaggio - Inside Elixir/Erlang - Codemotion Milan 2018
 
How to install-gammu
How to install-gammuHow to install-gammu
How to install-gammu
 
Composer Tutorial (PHP Hampshire Sept 2013)
Composer Tutorial (PHP Hampshire Sept 2013)Composer Tutorial (PHP Hampshire Sept 2013)
Composer Tutorial (PHP Hampshire Sept 2013)
 
Kannel configuration step by step with Motorolla Razer
Kannel configuration step by step with Motorolla RazerKannel configuration step by step with Motorolla Razer
Kannel configuration step by step with Motorolla Razer
 
Help, my computer is sluggish
Help, my computer is sluggishHelp, my computer is sluggish
Help, my computer is sluggish
 
The Shell Game Part 4: Bash Shortcuts
The Shell Game Part 4: Bash ShortcutsThe Shell Game Part 4: Bash Shortcuts
The Shell Game Part 4: Bash Shortcuts
 
QEMU Sandboxing for dummies
QEMU Sandboxing for dummiesQEMU Sandboxing for dummies
QEMU Sandboxing for dummies
 
Password Recovery
Password RecoveryPassword Recovery
Password Recovery
 
3PAR: HOW TO CHANGE THE IP ADDRESS OF HP 3PAR SAN
3PAR: HOW TO CHANGE THE IP ADDRESS OF HP 3PAR SAN3PAR: HOW TO CHANGE THE IP ADDRESS OF HP 3PAR SAN
3PAR: HOW TO CHANGE THE IP ADDRESS OF HP 3PAR SAN
 

En vedette

On-demand real time transcoding
On-demand real time transcoding On-demand real time transcoding
On-demand real time transcoding Zoltán Németh
 
DB séma kezelés Liquibase-el
DB séma kezelés Liquibase-elDB séma kezelés Liquibase-el
DB séma kezelés Liquibase-elZoltán Németh
 
Implementing DevOps In Practice
Implementing DevOps In PracticeImplementing DevOps In Practice
Implementing DevOps In PracticeZoltán Németh
 

En vedette (6)

On-demand real time transcoding
On-demand real time transcoding On-demand real time transcoding
On-demand real time transcoding
 
DB séma kezelés Liquibase-el
DB séma kezelés Liquibase-elDB séma kezelés Liquibase-el
DB séma kezelés Liquibase-el
 
Building our own CDN
Building our own CDNBuilding our own CDN
Building our own CDN
 
Implementing DevOps In Practice
Implementing DevOps In PracticeImplementing DevOps In Practice
Implementing DevOps In Practice
 
Culture @ Velocity UK
Culture @ Velocity UKCulture @ Velocity UK
Culture @ Velocity UK
 
Tepsi test de desarrollo psicomotor 2 - 5 a
Tepsi test de desarrollo psicomotor 2 - 5 aTepsi test de desarrollo psicomotor 2 - 5 a
Tepsi test de desarrollo psicomotor 2 - 5 a
 

Similaire à Daemons in PHP

Deep into your applications, performance & profiling
Deep into your applications, performance & profilingDeep into your applications, performance & profiling
Deep into your applications, performance & profilingFabien Arcellier
 
bettercap.pdf
bettercap.pdfbettercap.pdf
bettercap.pdfshehbaz15
 
Linux Security and How Web Browser Sandboxes Really Work (NDC Oslo 2017)
Linux Security  and How Web Browser Sandboxes Really Work (NDC Oslo 2017)Linux Security  and How Web Browser Sandboxes Really Work (NDC Oslo 2017)
Linux Security and How Web Browser Sandboxes Really Work (NDC Oslo 2017)Patricia Aas
 
Make your cheap VM fly
Make your cheap VM flyMake your cheap VM fly
Make your cheap VM flyCode Enigma
 
Hacking Highly Secured Enterprise Environments by Zoltan Balazs
Hacking Highly Secured Enterprise Environments by Zoltan BalazsHacking Highly Secured Enterprise Environments by Zoltan Balazs
Hacking Highly Secured Enterprise Environments by Zoltan BalazsShakacon
 
Profiling and optimizing go programs
Profiling and optimizing go programsProfiling and optimizing go programs
Profiling and optimizing go programsBadoo Development
 
Distributed Queue System using Gearman
Distributed Queue System using GearmanDistributed Queue System using Gearman
Distributed Queue System using GearmanEric Cho
 
Your Inner Sysadmin - LonestarPHP 2015
Your Inner Sysadmin - LonestarPHP 2015Your Inner Sysadmin - LonestarPHP 2015
Your Inner Sysadmin - LonestarPHP 2015Chris Tankersley
 
Deploying Foreman in Enterprise Environments
Deploying Foreman in Enterprise EnvironmentsDeploying Foreman in Enterprise Environments
Deploying Foreman in Enterprise Environmentsinovex GmbH
 
Linux Server Deep Dives (DrupalCon Amsterdam)
Linux Server Deep Dives (DrupalCon Amsterdam)Linux Server Deep Dives (DrupalCon Amsterdam)
Linux Server Deep Dives (DrupalCon Amsterdam)Amin Astaneh
 
Hacker Halted 2014 - Post-Exploitation After Having Remote Access
Hacker Halted 2014 - Post-Exploitation After Having Remote AccessHacker Halted 2014 - Post-Exploitation After Having Remote Access
Hacker Halted 2014 - Post-Exploitation After Having Remote AccessEC-Council
 
Drupal Efficiency using open source technologies from Sun
Drupal Efficiency using open source technologies from SunDrupal Efficiency using open source technologies from Sun
Drupal Efficiency using open source technologies from Sunsmattoon
 
Defcon 22-zoltan-balazs-bypass-firewalls-application-whiteli
Defcon 22-zoltan-balazs-bypass-firewalls-application-whiteliDefcon 22-zoltan-balazs-bypass-firewalls-application-whiteli
Defcon 22-zoltan-balazs-bypass-firewalls-application-whiteliPriyanka Aash
 
Drupal Efficiency - Coding, Deployment, Scaling
Drupal Efficiency - Coding, Deployment, ScalingDrupal Efficiency - Coding, Deployment, Scaling
Drupal Efficiency - Coding, Deployment, Scalingsmattoon
 
Demystifying the Go Scheduler
Demystifying the Go SchedulerDemystifying the Go Scheduler
Demystifying the Go Schedulermatthewrdale
 
Writing & Sharing Great Modules on the Puppet Forge
Writing & Sharing Great Modules on the Puppet ForgeWriting & Sharing Great Modules on the Puppet Forge
Writing & Sharing Great Modules on the Puppet ForgePuppet
 
A Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy SystemA Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy Systemadrian_nye
 
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기Ji-Woong Choi
 

Similaire à Daemons in PHP (20)

Deep into your applications, performance & profiling
Deep into your applications, performance & profilingDeep into your applications, performance & profiling
Deep into your applications, performance & profiling
 
bettercap.pdf
bettercap.pdfbettercap.pdf
bettercap.pdf
 
Us 17-krug-hacking-severless-runtimes
Us 17-krug-hacking-severless-runtimesUs 17-krug-hacking-severless-runtimes
Us 17-krug-hacking-severless-runtimes
 
Linux Security and How Web Browser Sandboxes Really Work (NDC Oslo 2017)
Linux Security  and How Web Browser Sandboxes Really Work (NDC Oslo 2017)Linux Security  and How Web Browser Sandboxes Really Work (NDC Oslo 2017)
Linux Security and How Web Browser Sandboxes Really Work (NDC Oslo 2017)
 
Make your cheap VM fly
Make your cheap VM flyMake your cheap VM fly
Make your cheap VM fly
 
Hpc4 linux advanced
Hpc4 linux advancedHpc4 linux advanced
Hpc4 linux advanced
 
Hacking Highly Secured Enterprise Environments by Zoltan Balazs
Hacking Highly Secured Enterprise Environments by Zoltan BalazsHacking Highly Secured Enterprise Environments by Zoltan Balazs
Hacking Highly Secured Enterprise Environments by Zoltan Balazs
 
Profiling and optimizing go programs
Profiling and optimizing go programsProfiling and optimizing go programs
Profiling and optimizing go programs
 
Distributed Queue System using Gearman
Distributed Queue System using GearmanDistributed Queue System using Gearman
Distributed Queue System using Gearman
 
Your Inner Sysadmin - LonestarPHP 2015
Your Inner Sysadmin - LonestarPHP 2015Your Inner Sysadmin - LonestarPHP 2015
Your Inner Sysadmin - LonestarPHP 2015
 
Deploying Foreman in Enterprise Environments
Deploying Foreman in Enterprise EnvironmentsDeploying Foreman in Enterprise Environments
Deploying Foreman in Enterprise Environments
 
Linux Server Deep Dives (DrupalCon Amsterdam)
Linux Server Deep Dives (DrupalCon Amsterdam)Linux Server Deep Dives (DrupalCon Amsterdam)
Linux Server Deep Dives (DrupalCon Amsterdam)
 
Hacker Halted 2014 - Post-Exploitation After Having Remote Access
Hacker Halted 2014 - Post-Exploitation After Having Remote AccessHacker Halted 2014 - Post-Exploitation After Having Remote Access
Hacker Halted 2014 - Post-Exploitation After Having Remote Access
 
Drupal Efficiency using open source technologies from Sun
Drupal Efficiency using open source technologies from SunDrupal Efficiency using open source technologies from Sun
Drupal Efficiency using open source technologies from Sun
 
Defcon 22-zoltan-balazs-bypass-firewalls-application-whiteli
Defcon 22-zoltan-balazs-bypass-firewalls-application-whiteliDefcon 22-zoltan-balazs-bypass-firewalls-application-whiteli
Defcon 22-zoltan-balazs-bypass-firewalls-application-whiteli
 
Drupal Efficiency - Coding, Deployment, Scaling
Drupal Efficiency - Coding, Deployment, ScalingDrupal Efficiency - Coding, Deployment, Scaling
Drupal Efficiency - Coding, Deployment, Scaling
 
Demystifying the Go Scheduler
Demystifying the Go SchedulerDemystifying the Go Scheduler
Demystifying the Go Scheduler
 
Writing & Sharing Great Modules on the Puppet Forge
Writing & Sharing Great Modules on the Puppet ForgeWriting & Sharing Great Modules on the Puppet Forge
Writing & Sharing Great Modules on the Puppet Forge
 
A Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy SystemA Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy System
 
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
 

Plus de Zoltán Németh

Reveal The Secrets of Your Videos
Reveal The Secrets of Your VideosReveal The Secrets of Your Videos
Reveal The Secrets of Your VideosZoltán Németh
 
Voxxed Days Belgrade 2017 - How not to do DevOps
Voxxed Days Belgrade 2017 - How not to do DevOpsVoxxed Days Belgrade 2017 - How not to do DevOps
Voxxed Days Belgrade 2017 - How not to do DevOpsZoltán Németh
 
Scalable service architectures @ VDB16
Scalable service architectures @ VDB16Scalable service architectures @ VDB16
Scalable service architectures @ VDB16Zoltán Németh
 
Scalable service architectures @ BWS16
Scalable service architectures @ BWS16Scalable service architectures @ BWS16
Scalable service architectures @ BWS16Zoltán Németh
 
Content protection with UMS
Content protection with UMSContent protection with UMS
Content protection with UMSZoltán Németh
 
Scalable Service Architectures
Scalable Service ArchitecturesScalable Service Architectures
Scalable Service ArchitecturesZoltán Németh
 

Plus de Zoltán Németh (6)

Reveal The Secrets of Your Videos
Reveal The Secrets of Your VideosReveal The Secrets of Your Videos
Reveal The Secrets of Your Videos
 
Voxxed Days Belgrade 2017 - How not to do DevOps
Voxxed Days Belgrade 2017 - How not to do DevOpsVoxxed Days Belgrade 2017 - How not to do DevOps
Voxxed Days Belgrade 2017 - How not to do DevOps
 
Scalable service architectures @ VDB16
Scalable service architectures @ VDB16Scalable service architectures @ VDB16
Scalable service architectures @ VDB16
 
Scalable service architectures @ BWS16
Scalable service architectures @ BWS16Scalable service architectures @ BWS16
Scalable service architectures @ BWS16
 
Content protection with UMS
Content protection with UMSContent protection with UMS
Content protection with UMS
 
Scalable Service Architectures
Scalable Service ArchitecturesScalable Service Architectures
Scalable Service Architectures
 

Dernier

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 

Dernier (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

Daemons in PHP

  • 1. 1 DAEMONS IN PHP Zoltán Németh Core Systems Manager @ Ustream We. Are. NOW PLAYING DAEMONS IN PHP 1 Mar 26, 2013 .
  • 2. CONTENTS        NOW PLAYING WHY???? The core: daemonizing Signal handling Init scripts Easy building of daemons The current package Open sourcing DAEMONS IN PHP 2 Mar 26, 2013
  • 3. WHY????  The need for daemons – Frequently running scheduled tasks – Async processing – Cron drawbacks:  Can do only minute level  Does not guarantee exact timing  Cron jobs cannot be monitored NOW PLAYING DAEMONS IN PHP 3 Mar 26, 2013
  • 4. WHY????  PHP had some problems in the early days – Hard to manage long running scripts – Memory leaks – Problems with forking – Handling code changes NOW PLAYING DAEMONS IN PHP 4 Mar 26, 2013
  • 5. WHY????  Why daemons in PHP? – Mostly PHP codebase – Duplication of business logic leads to hell  Lot of the logic codes used in daemons were already used on the site – PHP experience – Quick and easy development NOW PLAYING DAEMONS IN PHP 5 Mar 26, 2013
  • 6. DAEMONIZING – THE CONCEPT  At startup, fork a child and exit from the parent – Start a new background session for the child  In the child, have a loop which does the task  Calculate timing after each loop and use usleep for precision  Have a pidfile (for monit etc) NOW PLAYING DAEMONS IN PHP 6 Mar 26, 2013
  • 7. DAEMONIZING – THE CODE NOW PLAYING DAEMONS IN PHP 7 Mar 26, 2013
  • 8. DAEMONIZING – THE CODE NOW PLAYING DAEMONS IN PHP 8 Mar 26, 2013
  • 9. DAEMONIZING – THE CODE NOW PLAYING DAEMONS IN PHP 9 Mar 26, 2013
  • 10. THE MAIN LOOP NOW PLAYING DAEMONS IN PHP 10 Mar 26, 2013
  • 11. TIMING NOW PLAYING DAEMONS IN PHP 11 Mar 26, 2013
  • 12. MEMORY LEAK CHECKING NOW PLAYING DAEMONS IN PHP 12 Mar 26, 2013
  • 13. SIGNAL HANDLING  Before PHP 5.3 – declare(ticks=1); – Signal dispatch by php system, at every tick – Unreliable – Precise, fixed intervals  Handler functions with pcntl_signal NOW PLAYING DAEMONS IN PHP 13 Mar 26, 2013
  • 14. SIGNAL HANDLING  PHP 5.3 – declare(ticks=1); is deprecated – Signal dispatch by code: pcntl_signal_dispatch – More reliable – Not precise, changing intervals (code execution determines timing) NOW PLAYING DAEMONS IN PHP 14 Mar 26, 2013
  • 15. SIGNAL HANDLING NOW PLAYING DAEMONS IN PHP 15 Mar 26, 2013
  • 16. SIGNAL HANDLING NOW PLAYING DAEMONS IN PHP 16 Mar 26, 2013
  • 17. INIT SCRIPTS  Needed for monit, run daemons on startup, etc  In the beginning: separate init script for every daemon  Lot of copy-paste with minimal changing information  Hard to keep consistent: changes do not propagate NOW PLAYING DAEMONS IN PHP 17 Mar 26, 2013
  • 18. INIT SCRIPTS NOW PLAYING DAEMONS IN PHP 18 Mar 26, 2013
  • 19. INIT SCRIPTS  Conclusion: let’s have a common script in the repo  Take the name of the daemon as a parameter  Required: a class to run a daemon by its name – Daemon_Runner NOW PLAYING DAEMONS IN PHP 19 Mar 26, 2013
  • 20. DAEMON RUNNER AND BUILDER  Original setup: one php file for each daemon  Each has its own class definition – All variable initializations – All configurations  Constructing the object and all dependencies  Starting the daemon  Lot of boilerplate code  Daemon_Runner NOW PLAYING DAEMONS IN PHP 20 Mar 26, 2013
  • 21. THE BOILERPLATE NOW PLAYING DAEMONS IN PHP 21 Mar 26, 2013
  • 22. DAEMON RUNNER AND BUILDER  Concept: a generic Runner class to run a daemon based with a given task  Task: the repeatedly running part of the daemon  Ustream_Daemon_Task interface  Independent of the daemon configuration NOW PLAYING DAEMONS IN PHP 22 Mar 26, 2013
  • 23. DAEMON RUNNER AND BUILDER  Builder: a factory which creates the daemon object  All configuration options are handed over by the builder  Runner: call the builder and then run the resulting class  Configuration in .ini files NOW PLAYING DAEMONS IN PHP 23 Mar 26, 2013
  • 24. INI FILE EXAMPLE NOW PLAYING DAEMONS IN PHP 24 Mar 26, 2013
  • 25. BUILDER CALL, LIST OF OPTIONS NOW PLAYING DAEMONS IN PHP 25 Mar 26, 2013
  • 26. BUILDER CODE NOW PLAYING DAEMONS IN PHP 26 Mar 26, 2013
  • 27. AVAILABLE OPTIONS  Sleep: period length (running time is substracted)  Minimum sleep: if running time is too long  Factory: Task factory class  Instance: for multi instance daemons NOW PLAYING DAEMONS IN PHP 27 Mar 26, 2013
  • 28. THE PACKAGE     Ustream_Daemon_Daemon Ustream_Daemon_Builder Ustream_Daemon_Runner Ustream_Daemon_PreconfiguredTaskDelegator: a generic daemon class used by the builder. Runs a task  Ustream_Daemon_Logger: a file based logger for the daemon package. Should be PSR3 NOW PLAYING DAEMONS IN PHP 28 Mar 26, 2013
  • 29. THE PACKAGE - INTERFACES  Ustream_Daemon_Task – doTask()  Ustream_Daemon_TaskFactory – createTaskFor(Ustream_Daemon_Daemon $daemon)  Ustream_Daemon_Starter – start() NOW PLAYING DAEMONS IN PHP 29 Mar 26, 2013
  • 30. THE DAEMON MONITOR       Centralized status monitor system Every daemon reports status on UDP Server in node.js Displays info Sends commands: e.g. Stop Will be moved to a separate package NOW PLAYING DAEMONS IN PHP 30 Mar 26, 2013
  • 31. THE DAEMON MONITOR NOW PLAYING DAEMONS IN PHP 31 Mar 26, 2013
  • 32. OPEN SOURCING  On github: https://github.com/ustream  Some prerequisites: – Remove remaining Ustream codebase specific references – Move Daemon Monitor related stuff to separate package  Planned ETA in April NOW PLAYING DAEMONS IN PHP 32 Mar 26, 2013
  • 33. FURTHER PLANS  Debug mode: – remotely enabled – collect output and dump when stopped  Runtime setting of loglevel – Possibly from remote daemon monitor  Code coverage collecting NOW PLAYING DAEMONS IN PHP 33 Mar 26, 2013
  • 34. 34 QUESTIONS? We. Are. NOW PLAYING DAEMONS IN PHP 34 Mar 26, 2013 .