gearman_job_integration_test_002.phpt 1.4 KB

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