Download the PHP package mkrmr/emphloyer without Composer

On this page you can find all versions of the php package mkrmr/emphloyer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package emphloyer

Emphloyer

There comes a time in the life of a PHP application that async job processing becomes a requirement. If you want something flexible that you can easily adapt to fit in with your application's infrastucture, then Emphloyer may be what you are looking for.

Installation

You can install Emphloyer through composer with:

composer require mkrmr/emphloyer

Usage

Using Emphloyer is pretty simple, in your application code you queue up jobs and running Emphloyer's command line program processes the queue.

Before you can start using Emphloyer you need to:

Additionally you can use Emphloyer to schedule jobs like you would in the crontab, to do so you will need to hook up the scheduler with a backend as well.

Defining your own jobs

Here's a silly example of a job impementation:

Anything in the attributes array will get serialized when the job gets queued up. Note that the keys 'className' and 'type' are reserved and should not be used in your own job implementations.

The perform method is what is executed when Emphloyer runs the job, if this raises an exception then the job will fail.

When a job fails the mayTryAgain method determines whether it may be attempted again or not. You could for example implement retry behaviour by keeping track of the number of retries in your job's internal attributes. Note that changing the attributes during the perform method will not persist them in the backend because the perform method is executed in a forked process and never communicated back to the master process, instead implement the beforeFail hook in your job instance and have that update the attributes in the job's instance in the master process.

You can control the number of processes for jobs based on their type. When you inherit from the \Emphloyer\AbstractJob class the type will be set to 'job' by default, you can use the setType method to set a specific type on an instance before you enqueue it or you can override the $type instance variable in your class to set another default.

Hooking up a backend

Emphloyer manages its jobs through its pipeline, in order to feed jobs into the pipeline and to get jobs out of it you need to connect a backend to it. You can either use a backend that someone has built already (such as Emphloyer-PDO) or implement your own. To build your own backend you must implement the \Emphloyer\Pipeline\Backend interface.

To enable Emphloyer to run with the backend of your choice you need to create a configuration file that you reference at runtime, here's an annotated example:

After setting your configuration file you can have Emphloyer process jobs like so:

/path/to/project/vendor/bin/emphloyer -c /path/to/config_file.php

If you want to clear the Pipeline of jobs you can add --clear to the above command.

To enqueue jobs in your application code you need to instantiate a Pipeline with the appropriate backend as is done in the configuration file, you can then simply enqueue jobs by passing an instance to the enqueue method:

As you can see from the above snippet the enqueue method returns a job object, this is a new instance loaded with the attributes as returned by the backend's enqueue method. The backend should include a unique id attribute that can be used to identify the job (like the Employer-PDO backend does), this can be useful if you want to poll whether a job you queued up has been completed.

The AbstractJob class assumes this attribute is stored as the id field in the attributes array and provides the getId method to access it. To check on a job you can use the Pipeline's find method with the job id to load it, depending on the backend completed jobs may no longer be stored in which case that method will return null (the Employer-PDO backend will delete completed jobs from the database for example).

Besides using the pipeline you can also use the scheduler to run specific jobs at set intervals like you would in the crontab. To do so you will have to hookup the scheduler to a backend in the same configuration file where you setup the pipeline like so:

As with the Pipeline you can either use a backend that someone has built \ already (such as Emphloyer-PDO which will soon have a backend for the Scheduler) or implement your own. To build your own backend you must implement the \Emphloyer\Scheduler\Backend interface.

If you have followed along this README and started Emphloyer earlier you will have to stop and start it to start using the scheduler.

To schedule jobs you need to instantiate a Scheduler with the appropriate backend as is done in the configuration file, you can then schedule jobs by passing an instance of said job to the schedule method:

You can get insight into the schedule by using the allEntries method on the Scheduler which returns an iterator that returns ScheduleEntry objects. In addition to this the delete method can be used to delete a specific entry from the schedule.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Make your changes, please make sure you adhere to the Doctrine coding standard as much as possible (phpcs configuration is included)
  4. Commit your changes (git commit -am 'Add some feature')
  5. Push to the branch (git push origin my-new-feature)
  6. Create a new pull request on GitHub

All versions of emphloyer with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2.0
ext-posix Version *
ext-pcntl Version *
psr/log Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mkrmr/emphloyer contains the following files

Loading the files please wait ....