本文整理汇总了PHP中Resque::pid方法的典型用法代码示例。如果您正苦于以下问题:PHP Resque::pid方法的具体用法?PHP Resque::pid怎么用?PHP Resque::pid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Resque
的用法示例。
在下文中一共展示了Resque::pid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: redis
/**
* Return an instance of the Resque_Redis class instantiated for Resque.
*
* @return Resque_Redis Instance of Resque_Redis.
*/
public static function redis()
{
// Detect when the PID of the current process has changed (from a fork, etc)
// and force a reconnect to redis.
$pid = getmypid();
if (self::$pid !== $pid) {
self::$redis = null;
self::$pid = $pid;
}
if (!is_null(self::$redis)) {
return self::$redis;
}
$server = self::$redisServer;
if (empty($server)) {
$server = 'localhost:6379';
}
if (is_array($server)) {
require_once dirname(__FILE__) . '/Resque/RedisCluster.php';
self::$redis = new Resque_RedisCluster($server);
} else {
if (strpos($server, 'unix:') === false) {
list($host, $port) = explode(':', $server);
} else {
$host = $server;
$port = null;
}
require_once dirname(__FILE__) . '/Resque/Redis.php';
$redisInstance = new Resque_Redis($host, $port);
$redisInstance->prefix(self::$namespace);
self::$redis = $redisInstance;
}
self::$redis->select(self::$redisDatabase);
return self::$redis;
}
示例2: redis
/**
* Return an instance of the Resque_Redis class instantiated for Resque.
* 获取一个redis的实例
* @return Resque_Redis Instance of Resque_Redis.
*/
public static function redis()
{
// Detect when the PID of the current process has changed (from a fork, etc)
// and force a reconnect to redis.
// getmypid — 获取 PHP 进程的 ID
$pid = getmypid();
// 如果当前PHP进程的ID与类中定义的不同,清空redis实例,将类中定义的ID改为当前PHP进程的ID
if (self::$pid !== $pid) {
self::$redis = null;
self::$pid = $pid;
}
// redis实例存在,直接返回
if (!is_null(self::$redis)) {
return self::$redis;
}
// redis实例不存在,取出redis配置,默认为'localhost:6379'
$server = self::$redisServer;
if (empty($server)) {
$server = 'localhost:6379';
}
// 如果配置是个array,就会生成多个redis实例
// 配置项$server是[['host' => hostname0, 'port' => port0], ['host' => hostname1, 'port' => port1]]
// 也可以是['redis0' => ['host' => hostname0, 'port' => port0], 'redis1' => ['host' => hostname1, 'port' => port1]]
if (is_array($server)) {
require_once dirname(__FILE__) . '/Resque/RedisCluster.php';
self::$redis = new Resque_RedisCluster($server);
} else {
if (strpos($server, 'unix:') === false) {
// $server is '127.0.0.1:6379'
list($host, $port) = explode(':', $server);
} else {
// $server is 'unix:/tmp/redis.sock'
// 注:redis 默认没有开启unix socket,需要在/etc/redis/redis.conf中修改
$host = $server;
$port = null;
}
require_once dirname(__FILE__) . '/Resque/Redis.php';
self::$redis = new Resque_Redis($host, $port);
}
// 选择redis的数据库
self::$redis->select(self::$redisDatabase);
return self::$redis;
}