Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6024819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:12:39+00:00 2026-05-23T04:12:39+00:00

public GearmanTask GearmanClient::addTask ( string $function_name , string $workload [, mixed &$context [, string

  • 0
public GearmanTask GearmanClient::addTask  ( string $function_name  , string $workload  [, mixed &$context  [, string $unique  ]] )
public bool GearmanWorker::addFunction  ( string $function_name  , callback $function  [, mixed &$context  [, int $timeout  ]] )

These are class methods that can be used to integrate the two.
With these, how do you relate the workload with the called function?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:12:40+00:00Added an answer on May 23, 2026 at 4:12 am

    GearmanClient is used to submit a task. Normally this is done from a web page, or a script meant to read a list of tasks to be submitted.

    GearmanWorker is meant to be set up in such a way that many parallel ‘workers’ can be run at the same time. Logically, whatever a worker does should represent a single atomic unit of work. That can mean doing a single transformation of an object into another and saving it back to the database, or assembling and sending an html email for a single user. $function_name is a function that takes a single argument, which is a GearmanJob object.

    So, your controller script might look something like this.

      $gearman_params = json_encode( array(
          'id'       => 77,
          'options'  => array('push' => true),
      ) );
      $client = new GearmanClient();
      $client->doBackground( "widgetize", $gearman_params );
    

    Then, your worker will do something like this.

    $gmworker  = GearmanWorker;
    $gmworker->addFunction( "widgetize", "widgetize" );
    while( $gmworker->work() ) {  
    
    if ( $gmworker->returnCode() !== GEARMAN_SUCCESS ) {
        echo "Worker Terminated." . PHP_EOL ;
        break;
      }
    
    } // while *working*
    
    function widgetize( $job ) {
        $workload = json_decode( $job->workload() );
    
        /* do stuff */
    }
    

    A few things to keep in mind:

    • The worker script is designed to be long running script, hence the while loop. Make sure to set your timeout and memory limits appropriately.
    • It’s also good practice to give the worker a run limit. As in, only allow the worker to run a few times, and then exit; PHP still sucks with memory usage, and it can be hard to tell when a worker will be killed because it ran out of memory.
    • In the same vein it’s also best to design workers to be idempotent, so jobs can be resubmitted to workers if they fail.
    • The Client can submit jobs to the worker with different priorities, and they don’t neccessarily have to be run in the background, like the above example. They can be run so that the client blocks.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public static void main(String[] args) { List<? extends Object> mylist = new ArrayList<Object>(); mylist.add(Java);
public class Test { public static void main(String[] args) { } } class Outer
public class Address { public string ZipCode {get; set;} } public class Customer {
public static IQueryable<TResult> ApplySortFilter<T, TResult>(this IQueryable<T> query, string columnName) where T : EntityObject {
public class InvestorMailing { public string To { get; set; } public IEnumerable<string> Attachments
public static void main(String[] args) { int [][]shatner = new int[1][1]; int []rat =
public class abc1 { private String s; public abc1(String s){this.s=s;} public static void main(String
public class Foo{ public string Prop1 {get;set;} public string Prop2 {get;set;} public Foo(Foo source)
public static string GetUa(HttpRequest hr) { try { string visitorBrowser = hr.UserAgent.ToString(); string originalBrowser
public struct Items { public string Id; public string Name; } public Items[] _items

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.