Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add support for multiple worker dirs for pecl workers. PEAR requires …

…a constant with the dir name in it at this time so it can not support multiple worker dirs. Examples updated to show this working for PECL.
  • Loading branch information...
commit 76d86755341bc7b92e02561f8cfecb0dc3a36ef6 1 parent 8043c46
@brianlmoon authored
View
87 GearmanManager.php
@@ -426,11 +426,13 @@ protected function getopt() {
$this->worker_dir = "./workers";
}
- if(!file_exists($this->worker_dir)){
- $this->show_help("Worker dir ".$this->worker_dir." not found");
+ $dirs = explode(",", $this->worker_dir);
+ foreach($dirs as $dir){
+ if(!file_exists($dir)){
+ $this->show_help("Worker dir ".$dir." not found");
+ }
}
-
if(!empty($this->config['max_worker_lifetime'])){
$this->max_run_time = (int)$this->config['max_worker_lifetime'];
}
@@ -520,55 +522,60 @@ protected function load_workers() {
$this->functions = array();
- $worker_files = glob($this->worker_dir."/*.php");
+ $dirs = explode(",", $this->worker_dir);
- if (!empty($worker_files)) {
+ foreach($dirs as $dir){
- foreach($worker_files as $file){
+ $this->log("Loading workers in ".$dir);
- $function = substr(basename($file), 0, -4);
+ $worker_files = glob($dir."/*.php");
- /**
- * include workers
- */
- if (!empty($this->config['include'])) {
- if (!in_array($function, $this->config['include'])) {
- continue;
+ if (!empty($worker_files)) {
+
+ foreach($worker_files as $file){
+
+ $function = substr(basename($file), 0, -4);
+
+ /**
+ * include workers
+ */
+ if (!empty($this->config['include'])) {
+ if (!in_array($function, $this->config['include'])) {
+ continue;
+ }
}
- }
- /**
- * exclude workers
- */
- if (in_array($function, $this->config['exclude'])) {
- continue;
- }
+ /**
+ * exclude workers
+ */
+ if (in_array($function, $this->config['exclude'])) {
+ continue;
+ }
- if(!isset($this->functions[$function])){
- $this->functions[$function] = array();
- }
+ if(!isset($this->functions[$function])){
+ $this->functions[$function] = array();
+ }
- $min_count = max($this->do_all_count, 1);
- if(!empty($this->config['functions'][$function]['count'])){
- $min_count = max($this->config['functions'][$function]['count'], $this->do_all_count);
- }
+ $min_count = max($this->do_all_count, 1);
+ if(!empty($this->config['functions'][$function]['count'])){
+ $min_count = max($this->config['functions'][$function]['count'], $this->do_all_count);
+ }
- if(!empty($this->config['functions'][$function]['dedicated_count'])){
- $ded_count = $this->do_all_count + $this->config['functions'][$function]['dedicated_count'];
- } elseif(!empty($this->config["dedicated_count"])){
- $ded_count = $this->do_all_count + $this->config["dedicated_count"];
- } else {
- $ded_count = $min_count;
- }
+ if(!empty($this->config['functions'][$function]['dedicated_count'])){
+ $ded_count = $this->do_all_count + $this->config['functions'][$function]['dedicated_count'];
+ } elseif(!empty($this->config["dedicated_count"])){
+ $ded_count = $this->do_all_count + $this->config["dedicated_count"];
+ } else {
+ $ded_count = $min_count;
+ }
- $this->functions[$function]["count"] = max($min_count, $ded_count);
+ $this->functions[$function]["count"] = max($min_count, $ded_count);
- $this->functions[$function]['path'] = $file;
+ $this->functions[$function]['path'] = $file;
+ }
}
-
}
-
}
/**
@@ -611,8 +618,6 @@ protected function validate_workers(){
$this->log("Helper forked", GearmanManager::LOG_LEVEL_PROC_INFO);
- $this->log("Loading workers in ".$this->worker_dir);
-
$this->load_workers();
if(empty($this->functions)){
@@ -940,7 +945,7 @@ protected function show_help($msg = "") {
echo " -P PID_FILE File to write process ID out to\n";
echo " -u USERNAME Run wokers as USERNAME\n";
echo " -v Increase verbosity level by one\n";
- echo " -w DIR Directory where workers are located, defaults to ./workers\n";
+ echo " -w DIR Directory where workers are located, defaults to ./workers. If you are using PECL, you can provide multiple directories separated by a comma.\n";
echo " -x SECONDS Maximum seconds for a worker to live\n";
echo " -Z Parse the command line and config file then dump it to the screen and exit.\n";
echo "\n";
View
4 config-advanced.ini
@@ -9,7 +9,9 @@
[GearmanManager]
; workers can be found in this dir
-worker_dir=/some/dir/with/workers
+; separate multiple dirs with a comma
+; multiple dirs only supported by pecl workers
+worker_dir=./pecl-workers,./pecl-worker-classes
; All workers in worker_dir will be loaded
include=*
View
7 pecl-manager.php
@@ -96,7 +96,12 @@ public function do_job($job) {
if(empty($objects[$f]) && !function_exists($f) && !class_exists($f)){
- @include $this->worker_dir."/$f.php";
+ if(!isset($this->functions[$f])){
+ $this->log("Function $f is not a registered job name");
+ return;
+ }
+
+ @include $this->functions[$f]["path"];
if(class_exists($f) && method_exists($f, "run")){
View
0  pecl-workers/Sum.php → pecl-worker-classes/Sum.php
File renamed without changes
Please sign in to comment.
Something went wrong with that request. Please try again.