Open seyfer opened 9 years ago
If I should put worker just in .php file - how to load $serviceManager to this file?
Now i'm add function just to public/index.php
and have this error
hp public/index.php gearmantest --action=worker --execute=1
PHP Warning: GearmanWorker::register() expects parameter 1 to be string, array given in /var/www/host.com/vendor/mwillbanks/mw-gearman/src/mwGearman/Worker/Pecl.php on line 123
but i'm pass string as parameter, not array
Solved only with this syntax
/* @var $gearman \mwGearman\Worker\Pecl */
$gearman->getGearmanWorker()->addFunction('myJob', function ($job) {
$workload = $job->workload();
echo $workload . "\n";
});
So feature to register job from class or Closure should be implemented in module.
I suppose I could say I'm in a similar boat here trying to get things working. That being said I think I understand why the author of this module wrote things this way -- the Gearman extension appears to take in a string as a globally accessible function. Given that it seems that passing in an anonymous function, though intuitive and certainly my preference as well, it doesn't seem like it would work out given the way that the Gearman extension is written.
--> From the php docs: public bool GearmanWorker::register ( string $function_name [, int $timeout ] )
Registers a function name with the job server with an optional timeout. The timeout specifies how many seconds the server will wait before marking a job as failed. If the timeout is set to zero, there is no timeout. <-- end of documentation quote.
Now, all that being said -- what is the suggested way to register the globally accessible functions without polluting the rest of the application's namespace?
There is my error. I'm trying run it from Console controller.
Also I add function in this file (not in class)
What I'm doing wrong? Can you please provide full example?