Skip to content

Example of building a long running process, and making that a daemon.

Notifications You must be signed in to change notification settings

tjlytle/daemon-example

 
 

Repository files navigation

Building PHP Daemons & Long Running Processes

This code is example daemons and long running processes related to the talk / workshop. The various branches show the process of creation from initial simplistic concept to a well formed long running process or daemon. This means that:

The associated branches will be rebased against master any time an example is added / updated!

Setup

If you're attending this as a workshop (or maybe you just want to take the examples for a spin), you should have these setup before hand:

Since you generally learn better when you're comfortable, you can certainly just use your local development environment if you're comfortable with installing those few dependencies.

Docker

The included docker-compse.yml should create the containers needed, and allow you to use mysql and beanstalkd as the hostnames for those services.

To install dependencies using composer, use the composer docker image:

docker run --rm -it -v `pwd`:/app composer install

Since everything is CLI, the php container will exit immediately. Use docker-compose run to get a shell in the (really a) php container. You'll be dropped into the project root and your container will be on the same network as the other containers:

docker-compose run --rm php

To access the MySQL database via the cli client:

docker-compose run --rm mysql mysql -h mysql -u workshop -p

And to view a console of the beanstalk queue, visit: http://localhost:2080

For how to install docker and docker-compose visit the official install guide.

Vagrant

Note: Docker is the preferred way to get a dev environment; however, this should still work.

The included vagrant configuration and bootstrap script should take care of all setup without any change to your local system:

vagrant up
vagrant ssh
cd /vagrant

For how to install vagrant, visit the official install guide. You'll also need VirtualBox as this vagrant 'box' is a VirtualBox image.

Support

If you have any problems setting this up prior to the workshop: create an issue, ping tjlytle on Twitter, or send me an email (my name is tim and I own timlytle.net, I'm sure you can figure it out).

Configuration

Edit config.php.dist and add your twitter oauth tokens, as well as your Nexmo credentials. If you're not using vagrant, you may also need to update the database credentials. Once edited, rename to config.php.

Tutorial

The longer form hands on workshop (using all the examples) given at:

  • php[world] 2017
  • ZendCon 2016

Talk

Originally a local PHP meetup talk, the shorter version has been given as a talk (using the twitter example) at these meetups / conferences:

  • LVPHP
  • php[tek] 2015
  • Nomad PHP
  • LoneStar PHP 2016
  • OpenWest 2016

About

Example of building a long running process, and making that a daemon.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 95.6%
  • Shell 3.2%
  • Dockerfile 1.2%