echo.pl 848 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/perl
  2. #===============================================================================
  3. #
  4. # FILE: echo.pl
  5. #
  6. # USAGE: ./echo.pl
  7. #
  8. # DESCRIPTION: Echo back the workload.
  9. #
  10. # OPTIONS: ---
  11. # REQUIREMENTS: ---
  12. # BUGS: ---
  13. # NOTES: ---
  14. # AUTHOR: YOUR NAME (),
  15. # ORGANIZATION:
  16. # VERSION: 1.0
  17. # CREATED: 07/11/2012 04:02:42 PM
  18. # REVISION: ---
  19. #===============================================================================
  20. use Gearman::Worker;
  21. sub echo_worker
  22. {
  23. my $job = $_[0];
  24. my $workload= $job->arg;
  25. return $workload;
  26. }
  27. use strict;
  28. use warnings;
  29. my $host = 'localhost';
  30. my $port = '4730';
  31. my $servers = $host . ':' . $port;
  32. my $worker = Gearman::Worker->new;
  33. $worker->job_servers($servers);
  34. $worker->register_function( 'echo', \&echo_worker);
  35. $worker->work while 1;