0

machine 1 - client using PHP api

$client = new \GearmanClient();
$client->addServer(..);
$client->doBackground('demotask', 'hello world');

machine 2 - workers - not using PHP api, directly in bash:
gearman -w -f demotask -- php -f taskexecutor.php

The taskexecutor is getting run, but $argv does not contain hello world as expected.

P.S. not interested in PHP's API and a forever while loop on the second machine. I want gearman to start my script when it needs

Alex
  • 11,479
  • 6
  • 28
  • 50

1 Answers1

1

I really wouldn't recommend this implementation. If anything goes wrong in your php script, you won't be able to resubmit the job, or communicate with gearman.

Anwyays, the issue is that when the gearman client grabs the job, the job workload is passed to STDIN of your php process. So that means that $argv is always going to be empty. The parameters that you pass in can be read from STDIN like so;

$params = fgets(STDIN);

I'd recommend passing your params as JSON string so you can use simple functions like json_encode and json_decode, and not have to worry too much about structure or encoding, etc.

Chris Henry
  • 11,914
  • 3
  • 30
  • 31