Skip to content

504 Gateway Time-out on calling gearman runTasks #77

@ziyaindia

Description

@ziyaindia

My gearman client code is as below:

`class FNSGearman {
public $gmclient;
public $taskCount = 0;

public static $results = array();
public static function reset(){
GearmanResults::$results = array();
}

public static function completeCallback($task) {
$unique = $task->unique();
if ($unique != null) {
FNSGearman::$results[$unique] = $task->data();
}else {
array_push(FNSGearman::$results, $task->data());
}
}

public function addTask($func_name, $arguments, $context = null, $uid = null) {
$this->taskCount++;
$this->gmclient->addTask($func_name, $arguments, $context, $uid);
if ($this->taskCount == MAX_GEARMAN_TASKS) {
$this->gmclient->runTasks();
$this->taskCount = 0;
}
}

public function runTasks() {
var_dump($this->gmclient);
if ($this->taskCount > 0)
{
/echo $this->taskCount;die(' >> In runTasks function');
if (! $this->gmclient->runTasks())
{
echo "ERROR " . $this->gmclient->error() . "\n";
exit;
}
/
try {
// run the tasks in parallel (assuming multiple workers)
$this->gmclient->runTasks();
} catch (GearmanException $e) {
var_dump($e);
}
}
}

public function __construct() {
echo 'FNSGearman construct called.....';
$this->gmclient= new GearmanClient();
/* add the default server */
//$this->gmclient->addServer('localhost',4730);
$this->gmclient->addServer('127.0.0.1');
$this->gmclient->setCompleteCallback("FNSGearman::completeCallback");
}

}`
When I call runTasks it hangs my application execution

`$gm = new FNSGearman();

//$cdt = new FNSDateTime($_SESSION['timezone']);
//echo "1st timestamp: ".$cdt->dateTime->getTimestamp()."<br>";
//echo "1st timestamp: ".time()."<br>";

$tcount = count ( $trackers );

for ($i = 0, $counter = 0; $i < $tcount; $i++, $counter++) {
    $arguments = array('tid' => $trackers[$i], 'ts' => $timestamps, 'session' => $_SESSION);
    //print_r($arguments);
    $gm->addTask('dashboardAnalytics', json_encode($arguments), null, $trackers[$i]);//Commented By Ziya
    
}
$gm->runTasks();`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions