Dynamic Gearman Worker Functions in PHP

186 views
Skip to first unread message

emorling

unread,
Jan 12, 2012, 2:45:57 PM1/12/12
to gearman
Is it possible? The create_func function in PHP will dynamically
create a function, but there doesn't seem to be a way to rename it?
The reason for wanting to do this is to have a unique function for
each worker, so that the worker can be exited, e.g. with a name
"<process id>_stop_running".

thanks
Elia

Shane Harter

unread,
Jan 12, 2012, 2:50:59 PM1/12/12
to gea...@googlegroups.com
You don't need to name it -- that would kinda mitigate the point of anonymous functions. 

Instead, you can pass the output of create_function as a callback. So when you call addFunction(), give it whatever name you want, and then instead of passing in a callback, pass in the anonymous function. 

Look at the create_function docs, this should give you some guidance.

emorling

unread,
Jan 12, 2012, 2:58:27 PM1/12/12
to gearman
My goodness! You are absolutely right. I am an idiot. :)

Shane Harter

unread,
Jan 12, 2012, 3:05:16 PM1/12/12
to gea...@googlegroups.com
No, you're definitely not an idiot. Something like that is natural in JavaScript -- none of us really associates PHP with lambda calculus (and with good reason...). 

Soenke Ruempler

unread,
Jan 13, 2012, 3:36:58 PM1/13/12
to gea...@googlegroups.com, Shane Harter
Hi,

FYI: PHP 5.3 has native support for lambda / closures:

http://php.net/manual/en/functions.anonymous.php

signature.asc
Reply all
Reply to author
Forward
0 new messages