gearman_job_integration_test_010.phpt 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. --TEST--
  2. Test GearmanJob::workload(), GearmanJob::workloadSize()
  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. $worker->addServer($host, $port);
  20. $worker->addFunction(
  21. $job_name,
  22. function($job, $data) {
  23. print "GearmanJob::workload (OO): "
  24. . $job->workload()
  25. . PHP_EOL;
  26. print "GearmanJob::workloadSize (OO): "
  27. . $job->workloadSize()
  28. . PHP_EOL;
  29. }
  30. );
  31. $worker->work();
  32. $worker->unregister($job_name);
  33. // Wait for child
  34. $exit_status = 0;
  35. if (pcntl_wait($exit_status) <= 0) {
  36. print "pcntl_wait exited with error" . PHP_EOL;
  37. } else if (!pcntl_wifexited($exit_status)) {
  38. print "child exited with error" . PHP_EOL;
  39. }
  40. } else {
  41. //Child. This is the client. Don't echo anything here
  42. $client = new GearmanClient();
  43. if ($client->addServer($host, $port) !== true) {
  44. exit(1); // error
  45. };
  46. $tasks = [];
  47. $tasks[] = $client->addTask($job_name, "normal");
  48. $client->runTasks();
  49. if ($client->returnCode() != GEARMAN_SUCCESS) {
  50. exit(2); // error
  51. }
  52. exit(0);
  53. }
  54. print "Done";
  55. --EXPECTF--
  56. Start
  57. GearmanJob::workload (OO): normal
  58. GearmanJob::workloadSize (OO): 6
  59. Done