gearman_job_integration_test_008.phpt 1.4 KB

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