gearman_worker_integration_test_001.phpt 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. --TEST--
  2. Test Gearman worker methods
  3. --SKIPIF--
  4. <?php
  5. require_once('skipif.inc');
  6. require_once('skipifconnect.inc');
  7. ?>
  8. --FILE--
  9. <?php
  10. require_once('connect.inc');
  11. print "Start" . PHP_EOL;
  12. $job_name = uniqid();
  13. $pid = pcntl_fork();
  14. if ($pid == -1) {
  15. die("Could not fork");
  16. } else if ($pid > 0) {
  17. // Parent. This is the worker
  18. $worker = new GearmanWorker();
  19. print "addServer: " . var_export($worker->addServer($host, $port), true) . PHP_EOL;
  20. print "setTimeout: " . var_export($worker->setTimeout(100), true) . PHP_EOL;
  21. print "register: " . var_export($worker->register($job_name, 5), true) . PHP_EOL;
  22. print "register: " . var_export($worker->register($job_name . "1", 5), true) . PHP_EOL;
  23. print "register: " . var_export($worker->register($job_name . "2", 5), true) . PHP_EOL;
  24. print "register: " . var_export($worker->register($job_name . "3", 5), true) . PHP_EOL;
  25. print "addFunction: " . var_export(
  26. $worker->addFunction(
  27. $job_name,
  28. function($job) {
  29. print "workload: " . var_export($job->workload(), true) . PHP_EOL;
  30. }
  31. ), true
  32. ) . PHP_EOL;
  33. print "work: " . var_export($worker->work(), true) . PHP_EOL;
  34. print "unregister: " . var_export($worker->unregister($job_name), true) . PHP_EOL;
  35. print "unregisterAll: " . var_export($worker->unregisterAll(), true) . PHP_EOL;
  36. // Wait for child
  37. $exit_status = 0;
  38. if (pcntl_wait($exit_status) <= 0) {
  39. print "pcntl_wait exited with error" . PHP_EOL;
  40. } else if (!pcntl_wifexited($exit_status)) {
  41. print "child exited with error" . PHP_EOL;
  42. }
  43. } else {
  44. //Child. This is the client. Don't echo anything here
  45. $client = new GearmanClient();
  46. if ($client->addServer($host, $port) !== true) {
  47. exit(1); // error
  48. };
  49. $client->doBackground($job_name, "nothing");
  50. if ($client->returnCode() != GEARMAN_SUCCESS) {
  51. exit(2); // error
  52. }
  53. exit(0);
  54. }
  55. print "Done";
  56. --EXPECTF--
  57. Start
  58. addServer: true
  59. setTimeout: true
  60. register: true
  61. register: true
  62. register: true
  63. register: true
  64. addFunction: true
  65. workload: 'nothing'
  66. work: true
  67. unregister: true
  68. unregisterAll: true
  69. Done