mattdanger/phalcon-semaphore

Phalcon v1.4.x 版本的简单信号量组件

v1.1.0 2016-06-01 22:11 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:36:50 UTC


README

Phalcon PHP 的简单信号量组件

要求

  • Phalcon v1.4.x

安装

使用 Composer 安装

{
	"require": {
		"mattdanger/phalcon-semaphore": "1.*"
	}
}

创建一个名为 semaphore 的数据库表,其模式如下

CREATE TABLE `semaphore` (
  `name` varchar(255) NOT NULL DEFAULT '',
  `value` varchar(255) DEFAULT NULL,
  `timestamp` datetime DEFAULT NULL,
  PRIMARY KEY (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

然后添加服务

$di->set('semaphore', '\PhalconSemaphore\Semaphore');

如果您想使用不同的数据库表名,可以像这样初始化服务

$di->set('semaphore', function() use ($config){
  return new \PhalconSemaphore\Semaphore('my_table_name');
}, true);

使用方法

$this->semaphore->run(string $class, $string method, int $expiration_hours, array $args);

// Example without method parameters
$this->semaphore->run('MyNamespace\Models\Stat', 'calculate', 1);

// Example with method parameters
$this->semaphore->run('MyNamespace\Models\Stat', 'calculate', 1, array($arg1, $arg2, ...));