Giter Site home page Giter Site logo

gotask's Introduction

GoTask

English | 中文

Build Status

GoTask spawns a go process as a Swoole sidecar and establishes a bi-directional IPC to offload heavy-duties to Go. Think of it as a Swoole Taskworker in Go.

composer require hyperf/gotask

Feature

  • High performance with low footprint.
  • Based on Swoole 4 coroutine socket API.
  • Support Unix Socket, TCP and stdin/stdout pipes.
  • Support both PHP-to-Go and Go-to-PHP calls.
  • Automatic sidecar lifecycle management.
  • Correctly handle remote error.
  • Support both structural payload and binary payload.
  • Sidecar API compatible with net/rpc.
  • Baked-in connection pool.
  • Optionally integrated with Hyperf framework.

Perfect For

  • Blocking operations in Swoole, such as MongoDB queries.
  • CPU Intensive operations, such as encoding and decoding.
  • Leveraging Go eco-system, such as Kubernetes clients.

Requirement

  • PHP 7.2+
  • Go 1.13+
  • Swoole 4.4LTS+
  • Hyperf 1.1+ (optional)

Task Delivery Demo

package main

import (
    "github.com/hyperf/gotask/v2/pkg/gotask"
)

type App struct{}

func (a *App) Hi(name string, r *interface{}) error {
    *r = map[string]string{
        "hello": name,
    }
    return nil
}

func main() {
    gotask.SetAddress("127.0.0.1:6001")
    gotask.Register(new(App))
    gotask.Run()
}
<?php

use Hyperf\GoTask\IPC\SocketIPCSender;
use function Swoole\Coroutine\run;

require_once "../vendor/autoload.php";

run(function(){
    $task = new SocketIPCSender('127.0.0.1:6001');
    var_dump($task->call("App.Hi", "Hyperf"));
    // [ "hello" => "Hyperf" ]
});

Resources

English documentation is not yet complete! Please see examples first.

Benchmark

https://github.com/reasno/gotask-benchmark

Credit

gotask's People

Contributors

dependabot-preview[bot] avatar niexiawei avatar reasno avatar sy-records avatar

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.