>
> I've been playing with Gearman PHP extension for two weeks now. I'm
> struggling to guess the meanings of all methods on provided classes
> (no docs, what a joy).
I share your opinion completely. I started with creating some
documentation, but it was to tough.
> So, here's the thing. When using a client, if gearmand is down, I get
> a "could not connect" error. That's what I want. But when gearmand is
> up and there is no worker registered for the job i'm sending, client
> waits forever (or until PHP executing time limit is reached). I've
> been looking at constants defined by the extension and trying with
> setOptions on client and I couldn't do what I want. Is there any way
> to set a timeout for GearmanClient?
>
> One option of course is doing a job in background and then checking
> it's state with GearmanClient::jobStatus continuosly, giving up after
> certain time limit is reached (but how do i get a result from worker
> this way if i need it?).
How do you check the status of a background job? Do you have a snippet
of code for that?
Ex. this shows that I have two reverse task queued. Then I started up
the worker which drained the task.
% telnet localhost 4730
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
status
reverse 2 0 0
.
status
reverse 0 0 1
.
-James
On Fri, Aug 14, 2009 at 12:05:33AM -0700, nejc.jelovcan wrote:
> I've been playing with Gearman PHP extension for two weeks now. I'm
> struggling to guess the meanings of all methods on provided classes
> (no docs, what a joy).
Yeah, all I can say is they're coming, along with generic Gearman
docs as well. Unfortunately there is only reflection output, a few
examples, and this mailing list. We need more help if anyone is
interested in contributing!
> So, here's the thing. When using a client, if gearmand is down, I get
> a "could not connect" error. That's what I want. But when gearmand is
> up and there is no worker registered for the job i'm sending, client
> waits forever (or until PHP executing time limit is reached). I've
> been looking at constants defined by the extension and trying with
> setOptions on client and I couldn't do what I want. Is there any way
> to set a timeout for GearmanClient?
Not currently, but this will be added in the near future. This will
most likely be an option (like CLIENT_TIMEOUT or WORKER_TIMEOUT)
to wait inside of any client/worker function before returning. It
actually won't be difficult to do since everything is non-blocking
and this will just translate to a poll() timeout request.
> One option of course is doing a job in background and then checking
> it's state with GearmanClient::jobStatus continuosly, giving up after
> certain time limit is reached (but how do i get a result from worker
> this way if i need it?).
Like you said, hard to get your result back if you need it immediately,
foreground job is what you want.
> It would be great if at least the constants were listed somewhere with
> their meanings described. Some, are actual values, some are
> enumerators (0,1,2,3...), flags (2,4,8,16...). I'm having a hard time
> guessing which are relevant for my usage.
Probably not many. Again, something that will come with
documentation. The only flags you'll be concerned with are
gearman_client_options_t/gearman_worker_options_t (as defined in the
C header) options for now. There are not any yet that would help with
your timeout issue.
Thanks for your input, we're getting there. :)
-Eric
The timeouts, for both client and worker, are done in my development
branch. I need to check a couple more things, but this should be merged
into trunk tomorrow and released in 0.10 (C library) this week. The
PHP extension will also have the new functionality added and released
this week. C-library-based Perl and Python soon to follow as well,
I hope. :)
-Eric
If you want to share any code (or pseudo code) of how you think things
could work, please do. While the PHP module is starting to stablize,
we're still lookings for better ways of doing things. I know James
was still planning to do more with exception handling.
-Eric