Net_Gearman
[ class tree: Net_Gearman ] [ index: Net_Gearman ] [ all elements ]

Class: Net_Gearman_Worker

Source Location: /Net_Gearman-0.1.0/Net/Gearman/Worker.php

Class Overview


Gearman worker class


Author(s):

Copyright:

  • 2007-2008 Digg.com, Inc.

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 65]
Gearman worker class

Run an instance of a worker to listen for jobs. It then manages the running of jobs, etc.

  1.  <?php
  2.  
  3.  $servers = array(
  4.      '127.0.0.1:7003',
  5.      '127.0.0.1:7004'
  6.  );
  7.  
  8.  $abilities = array('HelloWorld''Foo''Bar');
  9.  
  10.  try {
  11.      $worker = new Net_Gearman_Worker($servers);
  12.      foreach ($abilities as $ability{
  13.          $worker->addAbility('HelloWorld');
  14.      }
  15.      $worker->beginWork();
  16.  catch (Net_Gearman_Exception $e{
  17.      echo $e->getMessage("\n";
  18.      exit;
  19.  }
  20.  
  21.  ?>



[ Top ]


Class Variables

$abilities = array()

[line 86]

Pool of worker abilities
  • Access: protected

Type:   array


[ Top ]

$callback = array(
        self::JOB_START     => array(),self::JOB_COMPLETE=>array(),self::JOB_FAIL=>array())

[line 97]

Callbacks registered for this worker

Type:   array


[ Top ]

$conn = array()

[line 72]

Pool of connections to Gearman servers
  • Access: protected

Type:   array


[ Top ]

$retryConn = array()

[line 79]

Pool of retry connections
  • Access: protected

Type:   array


[ Top ]



Method Detail

__construct (Constructor)   [line 123]

void __construct( array $servers)

Constructor

Parameters:

array   $servers   —  List of servers to connect to

[ Top ]

__destruct (Destructor)   [line 415]

void __destruct( )

Destructor
  • See: Net_Gearman_Worker::stop()
  • Access: public

[ Top ]

addAbility   [line 156]

void addAbility( string $ability, [integer $timeout = null])

Announce an ability to the job server

Parameters:

string   $ability   —  Name of functcion/ability
integer   $timeout   —  How long to give this job

[ Top ]

attachCallback   [line 328]

void attachCallback( callback $callback, [integer $type = self::JOB_COMPLETE])

Attach a callback
  • Throws: Net_Gearman_Exception
  • Access: public

Parameters:

callback   $callback   —  A valid PHP callback
integer   $type   —  Type of callback

[ Top ]

beginWork   [line 187]

void beginWork( [callback $monitor = null])

Begin working

This starts the worker on its journey of actually working. The first argument is a PHP callback to a function that can be used to monitor the worker. If no callback is provided then the worker works until it is killed. The monitor is passed two arguments; whether or not the worker is idle and when the last job was ran.


Parameters:

callback   $monitor   —  Function to monitor work

[ Top ]

complete   [line 366]

void complete( string $handle, string $job, array $result)

Run the complete callbacks
  • Access: protected

Parameters:

string   $handle   —  The job's Gearman handle
string   $job   —  The name of the job
array   $result   —  The job's returned result

[ Top ]

doWork   [line 272]

boolean doWork( resource $socket)

Listen on the socket for work

Sends the 'grab_job' command and then listens for either the 'noop' or the 'no_job' command to come back. If the 'job_assign' comes down the pipe then we run that job.


Parameters:

resource   $socket   —  The socket to work on

[ Top ]

endWork   [line 402]

void endWork( )

Stop working
  • Access: public

[ Top ]

fail   [line 386]

void fail( string $handle, string $job, PEAR_Exception $error)

Run the fail callbacks
  • Access: protected

Parameters:

string   $handle   —  The job's Gearman handle
string   $job   —  The name of the job
object   $error   —  The exception thrown

[ Top ]

start   [line 346]

void start( string $handle, string $job, mixed $args)

Run the job start callbacks
  • Access: protected

Parameters:

string   $handle   —  The job's Gearman handle
string   $job   —  The name of the job
mixed   $args   —  The job's argument list

[ Top ]

stopWork   [line 425]

boolean stopWork( )

Should we stop work?
  • Access: public

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:21:09 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.