Tarth
Tarth is an asynchronous, concurrent, distributed task process framework
Install / Use
/learn @pythias/TarthREADME
Tarth
Tarth is an asynchronous, concurrent, distributed task process framework.
Requires
- PHP 5.3 or Higher
- A POSIX compatible operating system (Linux, OSX, BSD)
- POSIX and PCNTL extensions for PHP
- Redis extensions
Features
- Asynchronous API callback, multi API callback
- Support timing callback, similar to crontab, but include retry, security, controllable options
- Support task number limit, speed controller
- Support callback priority level
- Stark Features
Usage
You can use Stark to start the timer and processor daemon:
php vendor/bin/stark -f scripts/timer.ini
php vendor/bin/stark -f scripts/processor.ini
Daemon
Use Stark
Task Tools
API
Class: \Tarth\Tool\Task
Create
static public function createApiTask($url, $method = 'GET', $params = array())
static public function createEmailTask($to, $subject, $message)
Control
static public function atomTask()
static public function exec()
static public function closeTask($taskId)
Security
static public function getTarthHeader(TaskInterface $task)
static public function isRequestFromTarth()
Samples
Normal task
php tests/normal_api_task.php
<?php
require_once __DIR__ . '/../vendor/autoload.php';
\Tarth\Tool\Redis::setCacheServer('127.0.0.1:6379');
\Tarth\Tool\Redis::setQueueServer('127.0.0.1:6379');
$task = \Tarth\Tool\Task::createApiTask('http://alleria.mcp.wap.grid.sina.com.cn/test/normal');
echo \Tarth\Tool\Task::exec();
Timer task
php tests/timer_task.php
<?php
require_once __DIR__ . '/../vendor/autoload.php';
$task = \Tarth\Tool\Task::createApiTask('http://alleria.mcp.wap.grid.sina.com.cn/test/normal?case=timer&time=' . time());
$task->runAfter(100);
echo \Tarth\Tool\Task::exec();
Multi task
php tests/multi_task.php
<?php
require_once __DIR__ . '/../vendor/autoload.php';
$task = \Tarth\Tool\Task::createApiTask('http://alleria.mcp.wap.grid.sina.com.cn/test/normal?case=atom&index=1&date=' . date('YmdHis'));
$task = \Tarth\Tool\Task::createApiTask('http://alleria.mcp.wap.grid.sina.com.cn/test/normal?case=atom&index=2&date=' . date('YmdHis'));
echo \Tarth\Tool\Task::exec();
Atom task
php tests/atom_task.php
<?php
require_once __DIR__ . '/../vendor/autoload.php';
$task = \Tarth\Tool\Task::createApiTask('http://alleria.mcp.wap.grid.sina.com.cn/test/normal?case=atom&index=1&date=' . date('YmdHis'));
$task = \Tarth\Tool\Task::createApiTask('http://alleria.mcp.wap.grid.sina.com.cn/test/normal?case=atom&index=2&date=' . date('YmdHis'));
$task = \Tarth\Tool\Task::atomTask();
$task->runAfter(600)->canClose();
echo \Tarth\Tool\Task::exec();
Configs
Daemon configs
See Stark
Redis configs
Config in daemon ini
[queue]
type = "redis"
host = "127.0.0.1"
port = "6379"
key = "tarth-queue-0 tarth-queue-1 tarth-queue-2"
Change in tools
<?php
\Tarth\Tool\Redis::setCacheServer('127.0.0.1:6379');
\Tarth\Tool\Redis::setQueueServer('127.0.0.1:6379');
Task Options
public function setPriority($level)
public function setMaxPerSecond($max)
public function setMaxPerMinute($max)
public function setMaxPerHour($max)
public function setMaxPerDay($max)
public function forbidDuplicate()
public function canClose()
public function runAt($timestamp)
public function runAfter($seconds)
Related Skills
node-connect
349.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.5kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
