Coder Social home page Coder Social logo

angela's Introduction

What is Angela?

Angela is a PHP worker/microservice framework based on ZeroMQ.

A typical Angela application consists of a job-server, a client to communicate with the server and workers which do the actual jobs. Angela provides the job server, the client and an API so you can easily implement your worker processes.

             +--------+
             | Client |
             +--------+
                 ^   
                 |   
                 v   
           +------------+
           | Job Server |
           +------------+
     +-------^   ^    ^------+
     |           |           |
     |           |           |
     v           v           v
+--------+   +--------+   +--------+
| Worker |   | Worker |   | Worker |
+--------+   +--------+   +--------+

Features

Job server

The job server is Angelas main process. It manages all your workers, listens for new job-requests, distributes these jobs to your workers and send back responses to the client. One server can manage multiple pools of workers and hence handle various types of jobs.

The job server will fire up worker-processes as defined in your project configuration. It will monitor the workers and for example restart processes if a worker crashes.

It is also capable of basic load-balancing so jobs will always be passed to the next idle worker.

Worker

Angela provides an API to easily build worker processes. Each worker typically does one kind of job (even though in can handle multiple types). You would than start multiple pools of worker processes which handle the different kind of jobs required in your application.

Example

<?php

class WorkerA extends \Nekudo\Angela\Worker
{
    public function taskA(string $payload) : string
    {
        // Do some work:
        sleep(1);

        // Return a response (needs to be string!):
        return strrev($payload);
    }
}

// Create new worker and register jobs:
$worker = new WorkerA;
$worker->registerJob('taskA', [$worker, 'taskA']);
$worker->run();

Client

The client is a simple class which allows you to send commands or job-requests to the server. It can send commands, normal jobs or background-jobs.

Normal jobs are blocking as the client will wait for a response. Background jobs however are non-blocking. They will be processed by the server but the client does not wait for a response.

Example

<?php
$client = new \Nekudo\Angela\Client;
$client->addServer('tcp://127.0.0.1:5551');
$result = $client->doNormal('taskA', 'some payload'); // result is "daolyap emos"
$client->close();

Requirements

Installation

Using composer:

composer require nekudo/angela

Documentation

Please see "example" folder for a dummy application. These are the most important files and commands:

  • config.php: Holds all necessary configuration for the server and worker pools.
  • control.php: A simple control-script to start/stop/restart your server and worker processes. Available commands are:
    • php control.php start
    • php control.php stop
    • php control.php restart
    • php control.php status
    • php control.php kill
    • php control.php flush-queue
  • client.php: An example client sending jobs to the job server.
  • worker/*.php: All your worker-scripts handling the actual jobs.

License

Released under the terms of the MIT license. See LICENSE file for details.

angela's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.