Gearman-server not found workers

288 views
Skip to first unread message

tham nguyen

unread,
Mar 17, 2012, 4:03:15 AM3/17/12
to gearman
I run work.php and client.php
on Gearman Server Status for localhost display:
Function Total Running Available Workers
reverse 1 0 0
title 0 0 0

Gearman-server not found workers. Why?
please help me

Herman Radtke

unread,
Mar 18, 2012, 1:49:46 AM3/18/12
to gea...@googlegroups.com
> Gearman-server not found workers. Why?
> please help me

I think you need to provide a little more information than that. What
workers are you trying to run?

--
Herman Radtke
herman...@gmail.com | http://hermanradtke.com

tham nguyen

unread,
Mar 18, 2012, 5:05:43 AM3/18/12
to gearman
My code

Client.php

<?php

# Create our client object.
$gmclient= new GearmanClient();

# Add default server (localhost).
$gmclient->addServer();

echo "Sending job\n";

# Send reverse job
do
{
$result = $gmclient->do("reverse", "Hello!");

# Check for various return packets and errors.
switch($gmclient->returnCode())
{
case GEARMAN_WORK_DATA:
echo "Data: $result\n";
break;
case GEARMAN_WORK_STATUS:
list($numerator, $denominator)= $gmclient->doStatus();
echo "Status: $numerator/$denominator complete\n";
break;
case GEARMAN_WORK_FAIL:
echo "Failed\n";
exit;
case GEARMAN_SUCCESS:
break;
default:
echo "RET: " . $gmclient->returnCode() . "\n";
exit;
}
}
while($gmclient->returnCode() != GEARMAN_SUCCESS);

?>


And Worker.php

<?php

echo "Starting\n";

# Create our worker object.
$gmworker= new GearmanWorker();

# Add default server (localhost).
$gmworker->addServer();

# Register function "reverse" with the server. Change the worker
function to
# "reverse_fn_fast" for a faster worker with no output.
$gmworker->addFunction("reverse", "reverse_fn");

print "Waiting for job...\n";
while($gmworker->work())
{
if ($gmworker->returnCode() != GEARMAN_SUCCESS)
{
echo "return_code: " . $gmworker->returnCode() . "\n";
break;
}
}

function reverse_fn($job)
{
echo "Received job: " . $job->handle() . "\n";

$workload = $job->workload();
$workload_size = $job->workloadSize();

echo "Workload: $workload ($workload_size)\n";

# This status loop is not needed, just showing how it works
for ($x= 0; $x < $workload_size; $x++)
{
echo "Sending status: " . ($x + 1) . "/$workload_size complete\n";
$job->sendStatus($x, $workload_size);
sleep(1);
}

$result= strrev($workload);
echo "Result: $result\n";

# Return what we want to send back to the client.
return $result;
}

# A much simpler and less verbose version of the above function would
be:
function reverse_fn_fast($job)
{
return strrev($job->workload());
}

?>

While I run terminal 1: ~$ php client.php
it display: Sending job .....

I run terminal 2: ~$ php worker.php
it display: Starting
Waiting for job...

Why client can't connect to worker?

I see in example, it display :
% php worker.php
Starting
Waiting for job...
Received job: H:foo.local:36
Workload: Hello! (6)
Sending status: 1/6 complete
Sending status: 2/6 complete
Sending status: 3/6 complete
Sending status: 4/6 complete
Sending status: 5/6 complete
Sending status: 6/6 complete
Result: !olleH

% php client.php
Starting
Sending job
Status: 1/6 complete
Status: 2/6 complete
Status: 3/6 complete
Status: 4/6 complete
Status: 5/6 complete
Status: 6/6 complete
Success: !olleH

Can you help me, please?

On 18 Tháng Ba, 12:49, Herman Radtke <hermanrad...@gmail.com> wrote:
> > Gearman-server not found workers. Why?
> > please help me
>
> I think you need to provide a little more information than that. What
> workers are you trying to run?
>
> --
> Herman Radtke
> hermanrad...@gmail.com |http://hermanradtke.com

Herman Radtke

unread,
Mar 18, 2012, 11:28:24 PM3/18/12
to gea...@googlegroups.com
> Can you help me, please?

This code works fine for me. Are you running gearmand (the gearman
daemon)? If you type "ps -e|grep gearman" you should be able to see if
it is running or not.

tham nguyen

unread,
Mar 19, 2012, 12:01:49 AM3/19/12
to gea...@googlegroups.com
thank you!
this is my result 

thamhut@ubuntu:~$ ps -e|grep gearman
 3109 ?        00:00:27 gearmand

and if i run: 

thamhut@ubuntu:~$ '/usr/sbin/gearmand' -vvv
 INFO Starting up
ERROR Address already in use 0.0.0.0:4730
ERROR Address already in use :::4730
FATAL _listen_init:Could not bind/listen to any addresses
 INFO Shutdown complete

gearmand can't find workers. I don't understand, please help me!

2012/3/19 Herman Radtke <herman...@gmail.com>

tham nguyen

unread,
Mar 19, 2012, 12:18:08 AM3/19/12
to gea...@googlegroups.com
I run them on the same machine
the worker can run as client default ?

2012/3/19 tham nguyen <sinhvienkh...@gmail.com>

Michael Tran

unread,
Mar 19, 2012, 12:06:30 AM3/19/12
to gea...@googlegroups.com
Kill all gearmand process and try again. Maybe a hidden process still alive and take the default port of gearmand
--
Sơn Trần
Technical Architect
Cellphone: 0909 219 168

tham nguyen

unread,
Mar 19, 2012, 9:55:55 AM3/19/12
to gea...@googlegroups.com
Thank  Michael Tran 
I had fixed according to your instructions . Again thank you very much.
Có phải anh là người Việt không ạ?  Em đang tìm hiểu về gearman nên còn kém, cảm ơn anh đã giúp, có gì mong anh chỉ bảo giúp em. Thank anh!

2012/3/19 Michael Tran <sontr...@gmail.com>

Michael Tran

unread,
Mar 19, 2012, 11:45:29 PM3/19/12
to gea...@googlegroups.com
@Tham Nguyen: yes, I am VNese. You can add my Y!M: no_longer16 :)
Reply all
Reply to author
Forward
0 new messages