hyperf / gotask
A replacement for Swoole TaskWorker in Go
Fund package maintenance!
Open Collective
hyperf.wiki/#/zh-cn/donate
Installs: 74 866
Dependents: 5
Suggesters: 0
Security: 0
Stars: 225
Watchers: 4
Forks: 27
Open Issues: 16
Requires
- php: >=8.1
- ext-swoole: >=5.0
- hyperf/pool: ^3.0
- hyperf/process: ^3.0
- spiral/goridge: ^2.4
- symfony/event-dispatcher: ^6.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.21
- hyperf/command: ^3.0
- hyperf/config: ^3.0
- hyperf/di: ^3.0
- hyperf/framework: ^3.0
- hyperf/testing: ^3.0
- mockery/mockery: ^1.6
- phpstan/phpstan: ^1.10
- swoole/ide-helper: ^5.0
- dev-master / 3.0.x-dev
- v3.0.1
- v3.0.0
- v3.0.0-alpha
- v2.2.10
- v2.2.9
- v2.2.8
- v2.2.7
- v2.2.6
- v2.2.5
- v2.2.4
- v2.2.3
- v2.2.2
- v2.2.1
- v2.2.0
- v2.1.x-dev
- v2.1.1
- v2.1.0
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.0.2
- v1.0.1
- v1.0.0
- v0.3.0
- v0.2.0
- v0.1.3
- v0.1.2
- 0.1.1
- 0.1.0
- 0.0.3
- dev-dependabot/composer/spiral/goridge-tw-2.4or-tw-4.0
- dev-dependabot/composer/symfony/event-dispatcher-tw-6.3or-tw-7.0
- dev-dependabot/composer/friendsofphp/php-cs-fixer-tw-2.14or-tw-3.0
- dev-perm
This package is auto-updated.
Last update: 2024-10-31 00:18:36 UTC
README
English | 中文
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
- https://github.com/spiral/goridge provides the IPC protocol.
- https://github.com/twose helps the creation of this project.