SlideShare a Scribd company logo
1 of 12
Download to read offline
Inner Symfony’s Daemons
Chris Ozog - Symfony CAMP UA 2015 Kiev, 24.10.2015
Random facts about me:
● CTO in Codesushi since 2012,
● Symfony enthusiast since 2011,
● Summoning daemons in PHP since 2010,
● Graduate of Computer science & Philosophy,
● PHP developer since 2007.
About me
Plan of the talk
● Daemons - do we need them?
● Usual way & Tools for creating daemons
● Symfony Daemons in PHP
● Daemons with Symfony Console Component
● Some things to consider
Couple of use cases for daemons:
● server:
- WebSockets,
- Socket protocols like SMPP.
● running processes more frequent than 1 minute.
Daemon (/ˈdiːmən/ or /ˈdeɪmən/) is a computer program that runs as a background
process, rather than being under the direct control of an interactive user. [wikipedia]
Daemons - why do we need them?
When creating a daemon PHP is not first thing that comes to you.
Usual way & tools for creating a daemon
● Single stack
● Reuse of components
● * We are still inside of Symfony *
Creating daemons in PHP
Simplest example in PHP:
while (true) { // your code };
problem with that solution: operating system will eventually kill that process.
Solution for that:
Heartbeat check, each cycle daemon puts timestamp in some file, then cron script reads that file
if timestamp is too much in the past it restarts our daemon.
Basically, this is hacking the operating system
instead of using its features.
Creating daemons in PHP
Creating daemons in PHP
There are 2 ways of doing it correctly:
● Forking - outdated:
http://kvz.io/blog/2009/01/09/create-daemons-in-php/
● Using upstart script - recommended
● Or other OS tool similar to upstart
Let’s look at some example daemon in pure PHP and upstart script.
Creating daemons in PHP
Let’s look at the same example of daemon but this time let’s use Symfony.
Wait, there’s bundle for that
https://github.com/mac-cain13/daemonizable-command
bundle provide some nice interface and gives us some debugging tools, but it is most
useful when we want to address the “cron scenario”
Daemons with
Symfony Console Component
Daemon is a process that is running constantly, so few things to consider:
● Connections to other services, like databases,
● Closing opened resources and reopening them,
● Memory leaks.
Some things to consider
Krzysztof Ożóg
CTO at Codesushi
chris@codesushi.co
codesushi.co
Questions

More Related Content

What's hot

Command & statement
Command & statementCommand & statement
Command & statementimrankhn22
 
Scalable Apache for Beginners
Scalable Apache for BeginnersScalable Apache for Beginners
Scalable Apache for Beginnerswebhostingguy
 
Interacting with XMPP using PHP
Interacting with XMPP using PHPInteracting with XMPP using PHP
Interacting with XMPP using PHPSudar Muthu
 
Introducing cvm...
Introducing cvm...Introducing cvm...
Introducing cvm...Offirmo
 
اسلاید اول جلسه دوم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه دوم کلاس پایتون برای هکرهای قانونیاسلاید اول جلسه دوم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه دوم کلاس پایتون برای هکرهای قانونیMohammad Reza Kamalifard
 
Intern_Poster_Xing_Wei
Intern_Poster_Xing_WeiIntern_Poster_Xing_Wei
Intern_Poster_Xing_WeiXing Wei
 
Rex - Deployment and Configuration Management
Rex - Deployment and Configuration ManagementRex - Deployment and Configuration Management
Rex - Deployment and Configuration Managementinovex GmbH
 
Js Test Driver, JsHamcrest, JsMockito
Js Test Driver, JsHamcrest, JsMockitoJs Test Driver, JsHamcrest, JsMockito
Js Test Driver, JsHamcrest, JsMockitoFredrik Wendt
 
7 covid19 - chp 06 - php loop (shared) -
7  covid19 - chp 06 - php loop (shared) -7  covid19 - chp 06 - php loop (shared) -
7 covid19 - chp 06 - php loop (shared) -YUSRA FERNANDO
 
Nimbix execution steps and sample exercise
Nimbix execution steps and sample exerciseNimbix execution steps and sample exercise
Nimbix execution steps and sample exerciseGanesan Narayanasamy
 
Installing Software, Part 2: Package Managers
Installing Software, Part 2: Package ManagersInstalling Software, Part 2: Package Managers
Installing Software, Part 2: Package ManagersKevin OBrien
 
HowTo Install openMPI on Ubuntu
HowTo Install openMPI on UbuntuHowTo Install openMPI on Ubuntu
HowTo Install openMPI on UbuntuA Jorge Garcia
 
Openoffice Portable In 2008conference
Openoffice Portable In 2008conferenceOpenoffice Portable In 2008conference
Openoffice Portable In 2008conferenceTony Liu
 
How to start Django automatically after restarting development or local syste...
How to start Django automatically after restarting development or local syste...How to start Django automatically after restarting development or local syste...
How to start Django automatically after restarting development or local syste...Vidhi_Khatri
 
How to download and install Python - lesson 2
How to download and install Python - lesson 2How to download and install Python - lesson 2
How to download and install Python - lesson 2Shohel Rana
 

What's hot (20)

Short intro to project butter
Short intro to project butterShort intro to project butter
Short intro to project butter
 
Command & statement
Command & statementCommand & statement
Command & statement
 
Scalable Apache for Beginners
Scalable Apache for BeginnersScalable Apache for Beginners
Scalable Apache for Beginners
 
Interacting with XMPP using PHP
Interacting with XMPP using PHPInteracting with XMPP using PHP
Interacting with XMPP using PHP
 
Introducing cvm...
Introducing cvm...Introducing cvm...
Introducing cvm...
 
اسلاید اول جلسه دوم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه دوم کلاس پایتون برای هکرهای قانونیاسلاید اول جلسه دوم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه دوم کلاس پایتون برای هکرهای قانونی
 
Intern_Poster_Xing_Wei
Intern_Poster_Xing_WeiIntern_Poster_Xing_Wei
Intern_Poster_Xing_Wei
 
Rex - Deployment and Configuration Management
Rex - Deployment and Configuration ManagementRex - Deployment and Configuration Management
Rex - Deployment and Configuration Management
 
Js Test Driver, JsHamcrest, JsMockito
Js Test Driver, JsHamcrest, JsMockitoJs Test Driver, JsHamcrest, JsMockito
Js Test Driver, JsHamcrest, JsMockito
 
7 covid19 - chp 06 - php loop (shared) -
7  covid19 - chp 06 - php loop (shared) -7  covid19 - chp 06 - php loop (shared) -
7 covid19 - chp 06 - php loop (shared) -
 
Nimbix execution steps and sample exercise
Nimbix execution steps and sample exerciseNimbix execution steps and sample exercise
Nimbix execution steps and sample exercise
 
Readme
ReadmeReadme
Readme
 
PowerShell 2.0 remoting
PowerShell 2.0 remotingPowerShell 2.0 remoting
PowerShell 2.0 remoting
 
Installing Software, Part 2: Package Managers
Installing Software, Part 2: Package ManagersInstalling Software, Part 2: Package Managers
Installing Software, Part 2: Package Managers
 
Linux tmpfs
Linux tmpfsLinux tmpfs
Linux tmpfs
 
Master C++ compilers
Master C++ compilersMaster C++ compilers
Master C++ compilers
 
HowTo Install openMPI on Ubuntu
HowTo Install openMPI on UbuntuHowTo Install openMPI on Ubuntu
HowTo Install openMPI on Ubuntu
 
Openoffice Portable In 2008conference
Openoffice Portable In 2008conferenceOpenoffice Portable In 2008conference
Openoffice Portable In 2008conference
 
How to start Django automatically after restarting development or local syste...
How to start Django automatically after restarting development or local syste...How to start Django automatically after restarting development or local syste...
How to start Django automatically after restarting development or local syste...
 
How to download and install Python - lesson 2
How to download and install Python - lesson 2How to download and install Python - lesson 2
How to download and install Python - lesson 2
 

Similar to Symfony Daemons: Creating and Managing Background Processes in PHP

Setting Up a Cloud Server - Part 1 - Transcript.pdf
Setting Up a Cloud Server - Part 1 - Transcript.pdfSetting Up a Cloud Server - Part 1 - Transcript.pdf
Setting Up a Cloud Server - Part 1 - Transcript.pdfShaiAlmog1
 
Create Your Own Framework by Fabien Potencier
Create Your Own Framework by Fabien PotencierCreate Your Own Framework by Fabien Potencier
Create Your Own Framework by Fabien PotencierHimel Nag Rana
 
Your Inner Sysadmin - Tutorial (SunshinePHP 2015)
Your Inner Sysadmin - Tutorial (SunshinePHP 2015)Your Inner Sysadmin - Tutorial (SunshinePHP 2015)
Your Inner Sysadmin - Tutorial (SunshinePHP 2015)Chris Tankersley
 
Php Conference Brazil - Phalcon Giant Killer
Php Conference Brazil - Phalcon Giant KillerPhp Conference Brazil - Phalcon Giant Killer
Php Conference Brazil - Phalcon Giant KillerJackson F. de A. Mafra
 
Why we choose Symfony2
Why we choose Symfony2Why we choose Symfony2
Why we choose Symfony2Merixstudio
 
Workshop For pycon13
Workshop For pycon13Workshop For pycon13
Workshop For pycon13Steven Pousty
 
Cfgmgmt Challenges aren't technical anymore
Cfgmgmt Challenges aren't technical anymoreCfgmgmt Challenges aren't technical anymore
Cfgmgmt Challenges aren't technical anymoreJulien Pivotto
 
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
 
Your Inner Sysadmin - MidwestPHP 2015
Your Inner Sysadmin - MidwestPHP 2015Your Inner Sysadmin - MidwestPHP 2015
Your Inner Sysadmin - MidwestPHP 2015Chris Tankersley
 
Concurrent Programming OpenMP @ Distributed System Discussion
Concurrent Programming OpenMP @ Distributed System DiscussionConcurrent Programming OpenMP @ Distributed System Discussion
Concurrent Programming OpenMP @ Distributed System DiscussionCherryBerry2
 
Free Mongo on OpenShift
Free Mongo on OpenShiftFree Mongo on OpenShift
Free Mongo on OpenShiftSteven Pousty
 
Automating Active Directory mgmt in PowerShell
Automating Active Directory mgmt in PowerShellAutomating Active Directory mgmt in PowerShell
Automating Active Directory mgmt in PowerShellConcentrated Technology
 
Software Quality Assurance Tooling - Wintersession 2024
Software Quality Assurance Tooling - Wintersession 2024Software Quality Assurance Tooling - Wintersession 2024
Software Quality Assurance Tooling - Wintersession 2024Henry Schreiner
 
Week 5
Week 5Week 5
Week 5A VD
 

Similar to Symfony Daemons: Creating and Managing Background Processes in PHP (20)

Setting Up a Cloud Server - Part 1 - Transcript.pdf
Setting Up a Cloud Server - Part 1 - Transcript.pdfSetting Up a Cloud Server - Part 1 - Transcript.pdf
Setting Up a Cloud Server - Part 1 - Transcript.pdf
 
Create Your Own Framework by Fabien Potencier
Create Your Own Framework by Fabien PotencierCreate Your Own Framework by Fabien Potencier
Create Your Own Framework by Fabien Potencier
 
Magento Meetup New Delhi- Console
Magento Meetup New Delhi- ConsoleMagento Meetup New Delhi- Console
Magento Meetup New Delhi- Console
 
Your Inner Sysadmin - Tutorial (SunshinePHP 2015)
Your Inner Sysadmin - Tutorial (SunshinePHP 2015)Your Inner Sysadmin - Tutorial (SunshinePHP 2015)
Your Inner Sysadmin - Tutorial (SunshinePHP 2015)
 
12 tricks to avoid hackers breaks your CI / CD
12 tricks to avoid hackers breaks your  CI / CD12 tricks to avoid hackers breaks your  CI / CD
12 tricks to avoid hackers breaks your CI / CD
 
Php Conference Brazil - Phalcon Giant Killer
Php Conference Brazil - Phalcon Giant KillerPhp Conference Brazil - Phalcon Giant Killer
Php Conference Brazil - Phalcon Giant Killer
 
X page developer
X page developerX page developer
X page developer
 
Why we choose Symfony2
Why we choose Symfony2Why we choose Symfony2
Why we choose Symfony2
 
Kohana 3.1
Kohana 3.1Kohana 3.1
Kohana 3.1
 
Modularity problems
Modularity  problemsModularity  problems
Modularity problems
 
Workshop For pycon13
Workshop For pycon13Workshop For pycon13
Workshop For pycon13
 
Cfgmgmt Challenges aren't technical anymore
Cfgmgmt Challenges aren't technical anymoreCfgmgmt Challenges aren't technical anymore
Cfgmgmt Challenges aren't technical anymore
 
Linux Server Deep Dives (DrupalCon Amsterdam)
Linux Server Deep Dives (DrupalCon Amsterdam)Linux Server Deep Dives (DrupalCon Amsterdam)
Linux Server Deep Dives (DrupalCon Amsterdam)
 
Framework
FrameworkFramework
Framework
 
Your Inner Sysadmin - MidwestPHP 2015
Your Inner Sysadmin - MidwestPHP 2015Your Inner Sysadmin - MidwestPHP 2015
Your Inner Sysadmin - MidwestPHP 2015
 
Concurrent Programming OpenMP @ Distributed System Discussion
Concurrent Programming OpenMP @ Distributed System DiscussionConcurrent Programming OpenMP @ Distributed System Discussion
Concurrent Programming OpenMP @ Distributed System Discussion
 
Free Mongo on OpenShift
Free Mongo on OpenShiftFree Mongo on OpenShift
Free Mongo on OpenShift
 
Automating Active Directory mgmt in PowerShell
Automating Active Directory mgmt in PowerShellAutomating Active Directory mgmt in PowerShell
Automating Active Directory mgmt in PowerShell
 
Software Quality Assurance Tooling - Wintersession 2024
Software Quality Assurance Tooling - Wintersession 2024Software Quality Assurance Tooling - Wintersession 2024
Software Quality Assurance Tooling - Wintersession 2024
 
Week 5
Week 5Week 5
Week 5
 

Recently uploaded

Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 

Recently uploaded (20)

Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 

Symfony Daemons: Creating and Managing Background Processes in PHP

  • 1. Inner Symfony’s Daemons Chris Ozog - Symfony CAMP UA 2015 Kiev, 24.10.2015
  • 2. Random facts about me: ● CTO in Codesushi since 2012, ● Symfony enthusiast since 2011, ● Summoning daemons in PHP since 2010, ● Graduate of Computer science & Philosophy, ● PHP developer since 2007. About me
  • 3. Plan of the talk ● Daemons - do we need them? ● Usual way & Tools for creating daemons ● Symfony Daemons in PHP ● Daemons with Symfony Console Component ● Some things to consider
  • 4. Couple of use cases for daemons: ● server: - WebSockets, - Socket protocols like SMPP. ● running processes more frequent than 1 minute. Daemon (/ˈdiːmən/ or /ˈdeɪmən/) is a computer program that runs as a background process, rather than being under the direct control of an interactive user. [wikipedia] Daemons - why do we need them?
  • 5. When creating a daemon PHP is not first thing that comes to you. Usual way & tools for creating a daemon
  • 6. ● Single stack ● Reuse of components ● * We are still inside of Symfony * Creating daemons in PHP
  • 7. Simplest example in PHP: while (true) { // your code }; problem with that solution: operating system will eventually kill that process. Solution for that: Heartbeat check, each cycle daemon puts timestamp in some file, then cron script reads that file if timestamp is too much in the past it restarts our daemon. Basically, this is hacking the operating system instead of using its features. Creating daemons in PHP
  • 8. Creating daemons in PHP There are 2 ways of doing it correctly: ● Forking - outdated: http://kvz.io/blog/2009/01/09/create-daemons-in-php/ ● Using upstart script - recommended ● Or other OS tool similar to upstart
  • 9. Let’s look at some example daemon in pure PHP and upstart script. Creating daemons in PHP
  • 10. Let’s look at the same example of daemon but this time let’s use Symfony. Wait, there’s bundle for that https://github.com/mac-cain13/daemonizable-command bundle provide some nice interface and gives us some debugging tools, but it is most useful when we want to address the “cron scenario” Daemons with Symfony Console Component
  • 11. Daemon is a process that is running constantly, so few things to consider: ● Connections to other services, like databases, ● Closing opened resources and reopening them, ● Memory leaks. Some things to consider
  • 12. Krzysztof Ożóg CTO at Codesushi chris@codesushi.co codesushi.co Questions