gearman_worker_014.phpt 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. --TEST--
  2. gearman_worker_work()
  3. --SKIPIF--
  4. <?php if (!extension_loaded("gearman")) print "skip";
  5. require_once('skipifconnect.inc');
  6. ?>
  7. --FILE--
  8. <?php
  9. $host = 'localhost';
  10. $port = 4730;
  11. $job = 'GenericTestJob';
  12. $func = 'do_work';
  13. $workload = '{"workload":"test"}';
  14. // Adding 2 jobs, one for OO and one for procedural
  15. $client = new GearmanClient();
  16. $client->addServer($host, $port);
  17. $handle = $client->doBackground($job, $workload);
  18. $client->doBackground($job, $workload);
  19. print "GearmanWorker::doBackground() (OO): ".(preg_match('/^H:'.gethostname().':\d+$/', $handle) === 1? 'Success' : 'Failure').PHP_EOL;
  20. $worker = new GearmanWorker();
  21. $worker->addServer($host, $port);
  22. $worker->addFunction($job, $func);
  23. print "GearmanWorker::work() (OO): ".($worker->work() === true ? 'Success' : 'Failure') . PHP_EOL;
  24. $worker2 = gearman_worker_create();
  25. gearman_worker_add_server($worker, $host, $port);
  26. gearman_worker_add_function($worker, $job, $func);
  27. print "gearman_worker_work() (Procedural): ".(gearman_worker_work($worker) === true ? 'Success' : 'Failure') . PHP_EOL;
  28. print "OK";
  29. function do_work($job) {
  30. print "Calling function ".__FUNCTION__.PHP_EOL;
  31. }
  32. ?>
  33. --EXPECT--
  34. GearmanWorker::doBackground() (OO): Success
  35. Calling function do_work
  36. GearmanWorker::work() (OO): Success
  37. Calling function do_work
  38. gearman_worker_work() (Procedural): Success
  39. OK