2017 © Pedro Peláez
 

library tarth

请求异步化框架

image

got/tarth

请求异步化框架

  • Tuesday, August 16, 2016
  • by pythias
  • Repository
  • 2 Watchers
  • 5 Stars
  • 33 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 3 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

Tarth

Tarth is an asynchronous, concurrent, distributed task process framework., (*1)

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:, (*2)

php vendor/bin/stark -f scripts/timer.ini
php vendor/bin/stark -f scripts/processor.ini

Daemon

Use Stark, (*3)

Task Tools

API

Class: \Tarth\Tool\Task, (*4)

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, (*5)

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)

The Versions

16/08 2016

dev-master

9999999-dev https://github.com/pythias/Tarth

请求异步化框架

  Sources   Download

MIT

The Requires

 

by Avatar chenjie

php async daemon

16/08 2016

1.0.8

1.0.8.0 https://github.com/pythias/Tarth

请求异步化框架

  Sources   Download

MIT

The Requires

 

by Avatar chenjie

php async daemon

22/07 2016

1.0.6

1.0.6.0 https://github.com/pythias/Tarth

请求异步化框架

  Sources   Download

MIT

The Requires

 

by Avatar chenjie

php async daemon

19/11 2015

1.0.4

1.0.4.0 https://github.com/pythias/Tarth

请求异步化框架

  Sources   Download

MIT

The Requires

 

by Avatar chenjie

php async daemon

19/11 2015

1.0.2

1.0.2.0 https://github.com/pythias/Tarth

请求异步化框架

  Sources   Download

MIT

The Requires

 

by Avatar chenjie

php async daemon

18/11 2015

v1.0.0

1.0.0.0 https://github.com/pythias/Tarth

请求异步化框架

  Sources   Download

MIT

The Requires

 

by Avatar chenjie

php async daemon