本文整理匯總了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;
}