client.rst 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. Client
  2. ======
  3. You can request a Job by using the gearman client.
  4. .. code-block:: php
  5. $this
  6. ->getContainer()
  7. ->get('gearman');
  8. Servers
  9. ~~~~~~~
  10. .. code-block:: php
  11. $gearman
  12. ->clearServers()
  13. ->setServer('127.1.1.1', 4677)
  14. ->addServer('127.1.1.1', 4678)
  15. ->addServer('127.1.1.1', 4679);
  16. - addServer: Add new server to requested client
  17. - setServer: Clean server list and set new server to requested client
  18. - clearServers: Clear server list
  19. .. note:: By default, if no server is set, gearman will use server defined as
  20. default in config.yml
  21. host: *127.0.0.1*
  22. port: *4730*
  23. Request a job
  24. ~~~~~~~~~~~~~
  25. .. code-block:: php
  26. $result = $gearman
  27. ->doJob('MmoreramerinoTestBundleServicesMyAcmeWorker~doSomething', json_encode(array('value1')));
  28. $returnCode = $gearman->getReturnCode();
  29. - doJob: Call the job and wait for the result
  30. - doNormalJob: Call the job and wait for the result ( Only newest gearman versions )
  31. - doHighJob: Call the job and wait for the result on High Preference
  32. - doLowJob: Call the job and wait for the result on Low Preference
  33. - doBackgroundJob: Call the job without waiting for the result.
  34. - It receives a job handle for the submitted job
  35. - doHighBackgroundJob: Call the job without waitting for the result on High Preference.
  36. - It receives a job handle for the submitted job
  37. - doLowBackgroundJob: Call the job without waitting for the result on Low Preference.
  38. - It receives a job handle for the submitted job
  39. - callJob: Call the job with default method.
  40. - Defined in settings, work annotations or the job annotations
  41. - getReturnCode: Retrieve the return code from the last requested job.
  42. Tasks
  43. ~~~~~
  44. .. code-block:: php
  45. $gearman
  46. ->addTask('MmoreramerinoTestBundleServicesMyAcmeWorker~doSomething', 'value1', $context1)
  47. ->addLowTask('MmoreramerinoTestBundleServicesMyAcmeWorker~doSomething', 'value2', $context2)
  48. ->addHighBackgroundTask('MmoreramerinoTestBundleServicesMyAcmeWorker~doSomething', 'value3', $context3)
  49. ->runTasks();
  50. - addTask: Adds a task to be run in parallel with other tasks
  51. - addTaskHigh: Add a high priority task to run in parallel
  52. - addTaskLow: Add a low priority task to run in parallel
  53. - addTaskBackground: Add a background task to be run in parallel
  54. - addTaskHighBackground: Add a high priority background task to be run in parallel
  55. - addTaskLowBackground: Add a low priority background task to be run in parallel
  56. - runTasks: Run a list of tasks in parallel