Skip to content

Repository files navigation

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"
)
typeAppstruct{}
func (a*App) Hi(namestring, r*interface{}) error {
*r=map[string]string{
"hello": name,
}
returnnil
}
funcmain() {
gotask.SetAddress("127.0.0.1:6001")
gotask.Register(new(App))
gotask.Run()
}
<?phpuseHyperf\GoTask\IPC\SocketIPCSender;
usefunctionSwoole\Coroutine\run;
require_once"../vendor/autoload.php";
run(function(){
$task = newSocketIPCSender('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

About

⚡️ A lightning speed replacement for Swoole TaskWorker in Go

Topics

Resources

Security policy

Stars

257 stars

Watchers

2 watching

Forks

Releases

Sponsor this project

Used by

Contributors

Languages