mrkcor / emphloyer-example

Example use of Emphloyer with PDO

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Emphloyer example with PDO

This project is a simple test example that uses Emphloyer with PDO. You can use this to play around with it a bit.

Setup

The easiest way to get up and running is by using Vagrant.

If you cannot or do not want to use Vagrant you will need to ensure that you have MySQL running on localhost and that the database emphloyer_example exists.

Install the dependencies with composer with

composer install

Set the following environmental variables:

  • DB_USER to the MySQL user (set this to root when using the Vagrant box)
  • DB_PWD to the MySQL user password (set this to an empty string when using the Vagrant box)
  • REGULAR_WORKERS to the number of concurrent workers to run for jobs of types other than 'priority'
  • PRIORITY_WORKERS to the number of concurrent workers to run for jobs of the type 'priority'

With bash you would execute:

export DB_USER=username
export DB_PWD=password
export REGULAR_WORKERS=2
export PRIORITY_WORKERS=1

To initialize the test database run:

php init.php

The init script drops the test tables and then re-creates them. It then proceeds to insert 100 jobs, 90 with type 'regular' and 10 with type 'priority'. It also sets up the scheduler to insert one priority job every minute.

Running the example

To run the example simply run (from the project root):

vendor/bin/emphloyer -c config.php

Once the output stops Emphloyer has finished processing jobs.

The test jobs insert records into the things table, you can check how long the entire process took with:

select (max(created_at) - min(created_at)) as runtime from things;

About

Example use of Emphloyer with PDO


Languages

Language:PHP 80.7%Language:Shell 19.3%