php_gearman.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. /*
  2. * Gearman PHP Extension
  3. *
  4. * Copyright (C) 2008 James M. Luedke <contact@jamesluedke.com>,
  5. * Eric Day <eday@oddments.org>
  6. * All rights reserved.
  7. *
  8. * Use and distribution licensed under the PHP license. See
  9. * the LICENSE file in this directory for full text.
  10. */
  11. #ifdef HAVE_CONFIG_H
  12. #include "config.h"
  13. #endif
  14. #include "php.h"
  15. #include "php_ini.h"
  16. #include "ext/standard/info.h"
  17. #include "php_gearman.h"
  18. #include "php_gearman_client.h"
  19. #include "php_gearman_task.h"
  20. #include "php_gearman_worker.h"
  21. #include "zend_exceptions.h"
  22. #include "zend_interfaces.h"
  23. #include "gearman_arginfo.h"
  24. #include <libgearman-1.0/gearman.h>
  25. #include <libgearman-1.0/interface/status.h>
  26. #include <libgearman-1.0/status.h>
  27. zend_class_entry *gearman_exception_ce;
  28. zend_class_entry *gearman_client_ce;
  29. zend_object_handlers gearman_client_obj_handlers;
  30. zend_class_entry *gearman_task_ce;
  31. zend_object_handlers gearman_task_obj_handlers;
  32. zend_class_entry *gearman_job_ce;
  33. zend_object_handlers gearman_job_obj_handlers;
  34. zend_class_entry *gearman_worker_ce;
  35. zend_object_handlers gearman_worker_obj_handlers;
  36. /* Custom malloc and free calls to avoid excessive buffer copies. */
  37. void *_php_malloc(size_t size, void *arg) {
  38. uint8_t *ret;
  39. ret = emalloc(size+1);
  40. ret[size]= 0;
  41. return ret;
  42. }
  43. void _php_free(void *ptr, void *arg) {
  44. efree(ptr);
  45. }
  46. /*
  47. * Functions from gearman.h
  48. */
  49. /* {{{ proto string gearman_version()
  50. Returns libgearman version */
  51. PHP_FUNCTION(gearman_version) {
  52. RETURN_STRING((char *)gearman_version());
  53. }
  54. /* }}} */
  55. /* {{{ proto string gearman_bugreport()
  56. Returns bug report URL string */
  57. PHP_FUNCTION(gearman_bugreport) {
  58. RETURN_STRING((char *)gearman_bugreport());
  59. }
  60. /* }}} */
  61. /* {{{ proto ?string gearman_verbose_name(constant verbose)
  62. Returns string with the name of the given verbose level */
  63. PHP_FUNCTION(gearman_verbose_name) {
  64. zend_long verbose;
  65. if (zend_parse_parameters(ZEND_NUM_ARGS(), "l",
  66. &verbose) == FAILURE) {
  67. php_error_docref(NULL, E_WARNING, "Unable to parse parameters.");
  68. RETURN_NULL();
  69. }
  70. if (verbose < 0) {
  71. php_error_docref(NULL, E_WARNING, "Input must be an integer greater than 0.");
  72. RETURN_NULL();
  73. }
  74. RETURN_STRING((char *)gearman_verbose_name(verbose));
  75. }
  76. /* }}} */
  77. PHP_MINIT_FUNCTION(gearman) {
  78. zend_class_entry ce;
  79. INIT_CLASS_ENTRY(ce, "GearmanClient", class_GearmanClient_methods);
  80. gearman_client_ce = zend_register_internal_class(&ce);
  81. gearman_client_ce->create_object = gearman_client_obj_new;
  82. memcpy(&gearman_client_obj_handlers, zend_get_std_object_handlers(), sizeof(gearman_client_obj_handlers));
  83. gearman_client_obj_handlers.offset = XtOffsetOf(gearman_client_obj, std);
  84. gearman_client_obj_handlers.free_obj = gearman_client_free_obj;
  85. INIT_CLASS_ENTRY(ce, "GearmanTask", class_GearmanTask_methods);
  86. gearman_task_ce = zend_register_internal_class(&ce);
  87. gearman_task_ce->create_object = gearman_task_obj_new;
  88. memcpy(&gearman_task_obj_handlers, zend_get_std_object_handlers(), sizeof(gearman_task_obj_handlers));
  89. gearman_task_obj_handlers.offset = XtOffsetOf(gearman_task_obj, std);
  90. gearman_task_obj_handlers.free_obj = gearman_task_free_obj;
  91. INIT_CLASS_ENTRY(ce, "GearmanWorker", class_GearmanWorker_methods);
  92. gearman_worker_ce = zend_register_internal_class(&ce);
  93. gearman_worker_ce->create_object = gearman_worker_obj_new;
  94. memcpy(&gearman_worker_obj_handlers, zend_get_std_object_handlers(), sizeof(gearman_worker_obj_handlers));
  95. gearman_worker_obj_handlers.offset = XtOffsetOf(gearman_worker_obj, std);
  96. INIT_CLASS_ENTRY(ce, "GearmanJob", class_GearmanJob_methods);
  97. gearman_job_ce = zend_register_internal_class(&ce);
  98. gearman_job_ce->create_object = gearman_job_obj_new;
  99. memcpy(&gearman_job_obj_handlers, zend_get_std_object_handlers(), sizeof(gearman_job_obj_handlers));
  100. gearman_job_obj_handlers.offset = XtOffsetOf(gearman_job_obj, std);
  101. /* XXX exception class */
  102. INIT_CLASS_ENTRY(ce, "GearmanException", class_GearmanException_methods)
  103. gearman_exception_ce = zend_register_internal_class_ex(&ce, zend_exception_get_default());
  104. gearman_exception_ce->ce_flags |= ZEND_ACC_FINAL;
  105. zend_declare_property_long(gearman_exception_ce, "code", sizeof("code")-1, 0, ZEND_ACC_PUBLIC);
  106. /* These are automatically generated from gearman_constants.h using
  107. const_gen.sh. Do not remove the CONST_GEN_* comments, this is how the
  108. script locates the correct location to replace. */
  109. /* CONST_GEN_START */
  110. REGISTER_STRING_CONSTANT("GEARMAN_DEFAULT_TCP_HOST",
  111. GEARMAN_DEFAULT_TCP_HOST,
  112. CONST_CS | CONST_PERSISTENT);
  113. REGISTER_LONG_CONSTANT("GEARMAN_DEFAULT_TCP_PORT",
  114. GEARMAN_DEFAULT_TCP_PORT,
  115. CONST_CS | CONST_PERSISTENT);
  116. REGISTER_LONG_CONSTANT("GEARMAN_DEFAULT_SOCKET_TIMEOUT",
  117. GEARMAN_DEFAULT_SOCKET_TIMEOUT,
  118. CONST_CS | CONST_PERSISTENT);
  119. REGISTER_LONG_CONSTANT("GEARMAN_DEFAULT_SOCKET_SEND_SIZE",
  120. GEARMAN_DEFAULT_SOCKET_SEND_SIZE,
  121. CONST_CS | CONST_PERSISTENT);
  122. REGISTER_LONG_CONSTANT("GEARMAN_DEFAULT_SOCKET_RECV_SIZE",
  123. GEARMAN_DEFAULT_SOCKET_RECV_SIZE,
  124. CONST_CS | CONST_PERSISTENT);
  125. REGISTER_LONG_CONSTANT("GEARMAN_MAX_ERROR_SIZE",
  126. GEARMAN_MAX_ERROR_SIZE,
  127. CONST_CS | CONST_PERSISTENT);
  128. REGISTER_LONG_CONSTANT("GEARMAN_PACKET_HEADER_SIZE",
  129. GEARMAN_PACKET_HEADER_SIZE,
  130. CONST_CS | CONST_PERSISTENT);
  131. REGISTER_LONG_CONSTANT("GEARMAN_JOB_HANDLE_SIZE",
  132. GEARMAN_JOB_HANDLE_SIZE,
  133. CONST_CS | CONST_PERSISTENT);
  134. REGISTER_LONG_CONSTANT("GEARMAN_OPTION_SIZE",
  135. GEARMAN_OPTION_SIZE,
  136. CONST_CS | CONST_PERSISTENT);
  137. REGISTER_LONG_CONSTANT("GEARMAN_UNIQUE_SIZE",
  138. GEARMAN_UNIQUE_SIZE,
  139. CONST_CS | CONST_PERSISTENT);
  140. REGISTER_LONG_CONSTANT("GEARMAN_MAX_COMMAND_ARGS",
  141. GEARMAN_MAX_COMMAND_ARGS,
  142. CONST_CS | CONST_PERSISTENT);
  143. REGISTER_LONG_CONSTANT("GEARMAN_ARGS_BUFFER_SIZE",
  144. GEARMAN_ARGS_BUFFER_SIZE,
  145. CONST_CS | CONST_PERSISTENT);
  146. REGISTER_LONG_CONSTANT("GEARMAN_SEND_BUFFER_SIZE",
  147. GEARMAN_SEND_BUFFER_SIZE,
  148. CONST_CS | CONST_PERSISTENT);
  149. REGISTER_LONG_CONSTANT("GEARMAN_RECV_BUFFER_SIZE",
  150. GEARMAN_RECV_BUFFER_SIZE,
  151. CONST_CS | CONST_PERSISTENT);
  152. REGISTER_LONG_CONSTANT("GEARMAN_WORKER_WAIT_TIMEOUT",
  153. GEARMAN_WORKER_WAIT_TIMEOUT,
  154. CONST_CS | CONST_PERSISTENT);
  155. REGISTER_LONG_CONSTANT("GEARMAN_SUCCESS",
  156. GEARMAN_SUCCESS,
  157. CONST_CS | CONST_PERSISTENT);
  158. REGISTER_LONG_CONSTANT("GEARMAN_IO_WAIT",
  159. GEARMAN_IO_WAIT,
  160. CONST_CS | CONST_PERSISTENT);
  161. REGISTER_LONG_CONSTANT("GEARMAN_SHUTDOWN",
  162. GEARMAN_SHUTDOWN,
  163. CONST_CS | CONST_PERSISTENT);
  164. REGISTER_LONG_CONSTANT("GEARMAN_SHUTDOWN_GRACEFUL",
  165. GEARMAN_SHUTDOWN_GRACEFUL,
  166. CONST_CS | CONST_PERSISTENT);
  167. REGISTER_LONG_CONSTANT("GEARMAN_ERRNO",
  168. GEARMAN_ERRNO,
  169. CONST_CS | CONST_PERSISTENT);
  170. REGISTER_LONG_CONSTANT("GEARMAN_EVENT",
  171. GEARMAN_EVENT,
  172. CONST_CS | CONST_PERSISTENT);
  173. REGISTER_LONG_CONSTANT("GEARMAN_TOO_MANY_ARGS",
  174. GEARMAN_TOO_MANY_ARGS,
  175. CONST_CS | CONST_PERSISTENT);
  176. REGISTER_LONG_CONSTANT("GEARMAN_NO_ACTIVE_FDS",
  177. GEARMAN_NO_ACTIVE_FDS,
  178. CONST_CS | CONST_PERSISTENT);
  179. REGISTER_LONG_CONSTANT("GEARMAN_INVALID_MAGIC",
  180. GEARMAN_INVALID_MAGIC,
  181. CONST_CS | CONST_PERSISTENT);
  182. REGISTER_LONG_CONSTANT("GEARMAN_INVALID_COMMAND",
  183. GEARMAN_INVALID_COMMAND,
  184. CONST_CS | CONST_PERSISTENT);
  185. REGISTER_LONG_CONSTANT("GEARMAN_INVALID_PACKET",
  186. GEARMAN_INVALID_PACKET,
  187. CONST_CS | CONST_PERSISTENT);
  188. REGISTER_LONG_CONSTANT("GEARMAN_UNEXPECTED_PACKET",
  189. GEARMAN_UNEXPECTED_PACKET,
  190. CONST_CS | CONST_PERSISTENT);
  191. REGISTER_LONG_CONSTANT("GEARMAN_GETADDRINFO",
  192. GEARMAN_GETADDRINFO,
  193. CONST_CS | CONST_PERSISTENT);
  194. REGISTER_LONG_CONSTANT("GEARMAN_NO_SERVERS",
  195. GEARMAN_NO_SERVERS,
  196. CONST_CS | CONST_PERSISTENT);
  197. REGISTER_LONG_CONSTANT("GEARMAN_LOST_CONNECTION",
  198. GEARMAN_LOST_CONNECTION,
  199. CONST_CS | CONST_PERSISTENT);
  200. REGISTER_LONG_CONSTANT("GEARMAN_MEMORY_ALLOCATION_FAILURE",
  201. GEARMAN_MEMORY_ALLOCATION_FAILURE,
  202. CONST_CS | CONST_PERSISTENT);
  203. REGISTER_LONG_CONSTANT("GEARMAN_JOB_EXISTS",
  204. GEARMAN_JOB_EXISTS,
  205. CONST_CS | CONST_PERSISTENT);
  206. REGISTER_LONG_CONSTANT("GEARMAN_JOB_QUEUE_FULL",
  207. GEARMAN_JOB_QUEUE_FULL,
  208. CONST_CS | CONST_PERSISTENT);
  209. REGISTER_LONG_CONSTANT("GEARMAN_SERVER_ERROR",
  210. GEARMAN_SERVER_ERROR,
  211. CONST_CS | CONST_PERSISTENT);
  212. REGISTER_LONG_CONSTANT("GEARMAN_WORK_ERROR",
  213. GEARMAN_WORK_ERROR,
  214. CONST_CS | CONST_PERSISTENT);
  215. REGISTER_LONG_CONSTANT("GEARMAN_WORK_DATA",
  216. GEARMAN_WORK_DATA,
  217. CONST_CS | CONST_PERSISTENT);
  218. REGISTER_LONG_CONSTANT("GEARMAN_WORK_WARNING",
  219. GEARMAN_WORK_WARNING,
  220. CONST_CS | CONST_PERSISTENT);
  221. REGISTER_LONG_CONSTANT("GEARMAN_WORK_STATUS",
  222. GEARMAN_WORK_STATUS,
  223. CONST_CS | CONST_PERSISTENT);
  224. REGISTER_LONG_CONSTANT("GEARMAN_WORK_EXCEPTION",
  225. GEARMAN_WORK_EXCEPTION,
  226. CONST_CS | CONST_PERSISTENT);
  227. REGISTER_LONG_CONSTANT("GEARMAN_WORK_FAIL",
  228. GEARMAN_WORK_FAIL,
  229. CONST_CS | CONST_PERSISTENT);
  230. REGISTER_LONG_CONSTANT("GEARMAN_NOT_CONNECTED",
  231. GEARMAN_NOT_CONNECTED,
  232. CONST_CS | CONST_PERSISTENT);
  233. REGISTER_LONG_CONSTANT("GEARMAN_COULD_NOT_CONNECT",
  234. GEARMAN_COULD_NOT_CONNECT,
  235. CONST_CS | CONST_PERSISTENT);
  236. REGISTER_LONG_CONSTANT("GEARMAN_SEND_IN_PROGRESS",
  237. GEARMAN_SEND_IN_PROGRESS,
  238. CONST_CS | CONST_PERSISTENT);
  239. REGISTER_LONG_CONSTANT("GEARMAN_RECV_IN_PROGRESS",
  240. GEARMAN_RECV_IN_PROGRESS,
  241. CONST_CS | CONST_PERSISTENT);
  242. REGISTER_LONG_CONSTANT("GEARMAN_NOT_FLUSHING",
  243. GEARMAN_NOT_FLUSHING,
  244. CONST_CS | CONST_PERSISTENT);
  245. REGISTER_LONG_CONSTANT("GEARMAN_DATA_TOO_LARGE",
  246. GEARMAN_DATA_TOO_LARGE,
  247. CONST_CS | CONST_PERSISTENT);
  248. REGISTER_LONG_CONSTANT("GEARMAN_INVALID_FUNCTION_NAME",
  249. GEARMAN_INVALID_FUNCTION_NAME,
  250. CONST_CS | CONST_PERSISTENT);
  251. REGISTER_LONG_CONSTANT("GEARMAN_INVALID_WORKER_FUNCTION",
  252. GEARMAN_INVALID_WORKER_FUNCTION,
  253. CONST_CS | CONST_PERSISTENT);
  254. REGISTER_LONG_CONSTANT("GEARMAN_NO_REGISTERED_FUNCTIONS",
  255. GEARMAN_NO_REGISTERED_FUNCTIONS,
  256. CONST_CS | CONST_PERSISTENT);
  257. REGISTER_LONG_CONSTANT("GEARMAN_NO_JOBS",
  258. GEARMAN_NO_JOBS,
  259. CONST_CS | CONST_PERSISTENT);
  260. REGISTER_LONG_CONSTANT("GEARMAN_ECHO_DATA_CORRUPTION",
  261. GEARMAN_ECHO_DATA_CORRUPTION,
  262. CONST_CS | CONST_PERSISTENT);
  263. REGISTER_LONG_CONSTANT("GEARMAN_NEED_WORKLOAD_FN",
  264. GEARMAN_NEED_WORKLOAD_FN,
  265. CONST_CS | CONST_PERSISTENT);
  266. REGISTER_LONG_CONSTANT("GEARMAN_PAUSE",
  267. GEARMAN_PAUSE,
  268. CONST_CS | CONST_PERSISTENT);
  269. REGISTER_LONG_CONSTANT("GEARMAN_UNKNOWN_STATE",
  270. GEARMAN_UNKNOWN_STATE,
  271. CONST_CS | CONST_PERSISTENT);
  272. REGISTER_LONG_CONSTANT("GEARMAN_PTHREAD",
  273. GEARMAN_PTHREAD,
  274. CONST_CS | CONST_PERSISTENT);
  275. REGISTER_LONG_CONSTANT("GEARMAN_PIPE_EOF",
  276. GEARMAN_PIPE_EOF,
  277. CONST_CS | CONST_PERSISTENT);
  278. REGISTER_LONG_CONSTANT("GEARMAN_QUEUE_ERROR",
  279. GEARMAN_QUEUE_ERROR,
  280. CONST_CS | CONST_PERSISTENT);
  281. REGISTER_LONG_CONSTANT("GEARMAN_FLUSH_DATA",
  282. GEARMAN_FLUSH_DATA,
  283. CONST_CS | CONST_PERSISTENT);
  284. REGISTER_LONG_CONSTANT("GEARMAN_SEND_BUFFER_TOO_SMALL",
  285. GEARMAN_SEND_BUFFER_TOO_SMALL,
  286. CONST_CS | CONST_PERSISTENT);
  287. REGISTER_LONG_CONSTANT("GEARMAN_IGNORE_PACKET",
  288. GEARMAN_IGNORE_PACKET,
  289. CONST_CS | CONST_PERSISTENT);
  290. REGISTER_LONG_CONSTANT("GEARMAN_UNKNOWN_OPTION",
  291. GEARMAN_UNKNOWN_OPTION,
  292. CONST_CS | CONST_PERSISTENT);
  293. REGISTER_LONG_CONSTANT("GEARMAN_TIMEOUT",
  294. GEARMAN_TIMEOUT,
  295. CONST_CS | CONST_PERSISTENT);
  296. REGISTER_LONG_CONSTANT("GEARMAN_MAX_RETURN",
  297. GEARMAN_MAX_RETURN,
  298. CONST_CS | CONST_PERSISTENT);
  299. REGISTER_LONG_CONSTANT("GEARMAN_VERBOSE_FATAL",
  300. GEARMAN_VERBOSE_FATAL,
  301. CONST_CS | CONST_PERSISTENT);
  302. REGISTER_LONG_CONSTANT("GEARMAN_VERBOSE_ERROR",
  303. GEARMAN_VERBOSE_ERROR,
  304. CONST_CS | CONST_PERSISTENT);
  305. REGISTER_LONG_CONSTANT("GEARMAN_VERBOSE_INFO",
  306. GEARMAN_VERBOSE_INFO,
  307. CONST_CS | CONST_PERSISTENT);
  308. REGISTER_LONG_CONSTANT("GEARMAN_VERBOSE_DEBUG",
  309. GEARMAN_VERBOSE_DEBUG,
  310. CONST_CS | CONST_PERSISTENT);
  311. REGISTER_LONG_CONSTANT("GEARMAN_VERBOSE_CRAZY",
  312. GEARMAN_VERBOSE_CRAZY,
  313. CONST_CS | CONST_PERSISTENT);
  314. REGISTER_LONG_CONSTANT("GEARMAN_VERBOSE_MAX",
  315. GEARMAN_VERBOSE_MAX,
  316. CONST_CS | CONST_PERSISTENT);
  317. REGISTER_LONG_CONSTANT("GEARMAN_NON_BLOCKING",
  318. GEARMAN_NON_BLOCKING,
  319. CONST_CS | CONST_PERSISTENT);
  320. REGISTER_LONG_CONSTANT("GEARMAN_DONT_TRACK_PACKETS",
  321. GEARMAN_DONT_TRACK_PACKETS,
  322. CONST_CS | CONST_PERSISTENT);
  323. REGISTER_LONG_CONSTANT("GEARMAN_CON_READY",
  324. GEARMAN_CON_READY,
  325. CONST_CS | CONST_PERSISTENT);
  326. REGISTER_LONG_CONSTANT("GEARMAN_CON_PACKET_IN_USE",
  327. GEARMAN_CON_PACKET_IN_USE,
  328. CONST_CS | CONST_PERSISTENT);
  329. REGISTER_LONG_CONSTANT("GEARMAN_CON_EXTERNAL_FD",
  330. GEARMAN_CON_EXTERNAL_FD,
  331. CONST_CS | CONST_PERSISTENT);
  332. REGISTER_LONG_CONSTANT("GEARMAN_CON_IGNORE_LOST_CONNECTION",
  333. GEARMAN_CON_IGNORE_LOST_CONNECTION,
  334. CONST_CS | CONST_PERSISTENT);
  335. REGISTER_LONG_CONSTANT("GEARMAN_CON_CLOSE_AFTER_FLUSH",
  336. GEARMAN_CON_CLOSE_AFTER_FLUSH,
  337. CONST_CS | CONST_PERSISTENT);
  338. REGISTER_LONG_CONSTANT("GEARMAN_CON_SEND_STATE_NONE",
  339. GEARMAN_CON_SEND_STATE_NONE,
  340. CONST_CS | CONST_PERSISTENT);
  341. REGISTER_LONG_CONSTANT("GEARMAN_CON_RECV_STATE_READ_DATA",
  342. GEARMAN_CON_RECV_STATE_READ_DATA,
  343. CONST_CS | CONST_PERSISTENT);
  344. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_TEXT",
  345. GEARMAN_COMMAND_TEXT,
  346. CONST_CS | CONST_PERSISTENT);
  347. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_CAN_DO",
  348. GEARMAN_COMMAND_CAN_DO,
  349. CONST_CS | CONST_PERSISTENT);
  350. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_CANT_DO",
  351. GEARMAN_COMMAND_CANT_DO,
  352. CONST_CS | CONST_PERSISTENT);
  353. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_RESET_ABILITIES",
  354. GEARMAN_COMMAND_RESET_ABILITIES,
  355. CONST_CS | CONST_PERSISTENT);
  356. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_PRE_SLEEP",
  357. GEARMAN_COMMAND_PRE_SLEEP,
  358. CONST_CS | CONST_PERSISTENT);
  359. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_UNUSED",
  360. GEARMAN_COMMAND_UNUSED,
  361. CONST_CS | CONST_PERSISTENT);
  362. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_NOOP",
  363. GEARMAN_COMMAND_NOOP,
  364. CONST_CS | CONST_PERSISTENT);
  365. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_SUBMIT_JOB",
  366. GEARMAN_COMMAND_SUBMIT_JOB,
  367. CONST_CS | CONST_PERSISTENT);
  368. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_JOB_CREATED",
  369. GEARMAN_COMMAND_JOB_CREATED,
  370. CONST_CS | CONST_PERSISTENT);
  371. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_GRAB_JOB",
  372. GEARMAN_COMMAND_GRAB_JOB,
  373. CONST_CS | CONST_PERSISTENT);
  374. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_NO_JOB",
  375. GEARMAN_COMMAND_NO_JOB,
  376. CONST_CS | CONST_PERSISTENT);
  377. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_JOB_ASSIGN",
  378. GEARMAN_COMMAND_JOB_ASSIGN,
  379. CONST_CS | CONST_PERSISTENT);
  380. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_WORK_STATUS",
  381. GEARMAN_COMMAND_WORK_STATUS,
  382. CONST_CS | CONST_PERSISTENT);
  383. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_WORK_COMPLETE",
  384. GEARMAN_COMMAND_WORK_COMPLETE,
  385. CONST_CS | CONST_PERSISTENT);
  386. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_WORK_FAIL",
  387. GEARMAN_COMMAND_WORK_FAIL,
  388. CONST_CS | CONST_PERSISTENT);
  389. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_GET_STATUS",
  390. GEARMAN_COMMAND_GET_STATUS,
  391. CONST_CS | CONST_PERSISTENT);
  392. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_ECHO_REQ",
  393. GEARMAN_COMMAND_ECHO_REQ,
  394. CONST_CS | CONST_PERSISTENT);
  395. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_ECHO_RES",
  396. GEARMAN_COMMAND_ECHO_RES,
  397. CONST_CS | CONST_PERSISTENT);
  398. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_SUBMIT_JOB_BG",
  399. GEARMAN_COMMAND_SUBMIT_JOB_BG,
  400. CONST_CS | CONST_PERSISTENT);
  401. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_ERROR",
  402. GEARMAN_COMMAND_ERROR,
  403. CONST_CS | CONST_PERSISTENT);
  404. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_STATUS_RES",
  405. GEARMAN_COMMAND_STATUS_RES,
  406. CONST_CS | CONST_PERSISTENT);
  407. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_SUBMIT_JOB_HIGH",
  408. GEARMAN_COMMAND_SUBMIT_JOB_HIGH,
  409. CONST_CS | CONST_PERSISTENT);
  410. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_SET_CLIENT_ID",
  411. GEARMAN_COMMAND_SET_CLIENT_ID,
  412. CONST_CS | CONST_PERSISTENT);
  413. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_CAN_DO_TIMEOUT",
  414. GEARMAN_COMMAND_CAN_DO_TIMEOUT,
  415. CONST_CS | CONST_PERSISTENT);
  416. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_ALL_YOURS",
  417. GEARMAN_COMMAND_ALL_YOURS,
  418. CONST_CS | CONST_PERSISTENT);
  419. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_WORK_EXCEPTION",
  420. GEARMAN_COMMAND_WORK_EXCEPTION,
  421. CONST_CS | CONST_PERSISTENT);
  422. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_OPTION_REQ",
  423. GEARMAN_COMMAND_OPTION_REQ,
  424. CONST_CS | CONST_PERSISTENT);
  425. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_OPTION_RES",
  426. GEARMAN_COMMAND_OPTION_RES,
  427. CONST_CS | CONST_PERSISTENT);
  428. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_WORK_DATA",
  429. GEARMAN_COMMAND_WORK_DATA,
  430. CONST_CS | CONST_PERSISTENT);
  431. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_WORK_WARNING",
  432. GEARMAN_COMMAND_WORK_WARNING,
  433. CONST_CS | CONST_PERSISTENT);
  434. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_GRAB_JOB_UNIQ",
  435. GEARMAN_COMMAND_GRAB_JOB_UNIQ,
  436. CONST_CS | CONST_PERSISTENT);
  437. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_JOB_ASSIGN_UNIQ",
  438. GEARMAN_COMMAND_JOB_ASSIGN_UNIQ,
  439. CONST_CS | CONST_PERSISTENT);
  440. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_SUBMIT_JOB_HIGH_BG",
  441. GEARMAN_COMMAND_SUBMIT_JOB_HIGH_BG,
  442. CONST_CS | CONST_PERSISTENT);
  443. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_SUBMIT_JOB_LOW",
  444. GEARMAN_COMMAND_SUBMIT_JOB_LOW,
  445. CONST_CS | CONST_PERSISTENT);
  446. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_SUBMIT_JOB_LOW_BG",
  447. GEARMAN_COMMAND_SUBMIT_JOB_LOW_BG,
  448. CONST_CS | CONST_PERSISTENT);
  449. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_SUBMIT_JOB_SCHED",
  450. GEARMAN_COMMAND_SUBMIT_JOB_SCHED,
  451. CONST_CS | CONST_PERSISTENT);
  452. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_SUBMIT_JOB_EPOCH",
  453. GEARMAN_COMMAND_SUBMIT_JOB_EPOCH,
  454. CONST_CS | CONST_PERSISTENT);
  455. REGISTER_LONG_CONSTANT("GEARMAN_COMMAND_MAX",
  456. GEARMAN_COMMAND_MAX,
  457. CONST_CS | CONST_PERSISTENT);
  458. REGISTER_LONG_CONSTANT("GEARMAN_TASK_STATE_NEW",
  459. GEARMAN_TASK_STATE_NEW,
  460. CONST_CS | CONST_PERSISTENT);
  461. REGISTER_LONG_CONSTANT("GEARMAN_TASK_STATE_SUBMIT",
  462. GEARMAN_TASK_STATE_SUBMIT,
  463. CONST_CS | CONST_PERSISTENT);
  464. REGISTER_LONG_CONSTANT("GEARMAN_TASK_STATE_WORKLOAD",
  465. GEARMAN_TASK_STATE_WORKLOAD,
  466. CONST_CS | CONST_PERSISTENT);
  467. REGISTER_LONG_CONSTANT("GEARMAN_TASK_STATE_WORK",
  468. GEARMAN_TASK_STATE_WORK,
  469. CONST_CS | CONST_PERSISTENT);
  470. REGISTER_LONG_CONSTANT("GEARMAN_TASK_STATE_CREATED",
  471. GEARMAN_TASK_STATE_CREATED,
  472. CONST_CS | CONST_PERSISTENT);
  473. REGISTER_LONG_CONSTANT("GEARMAN_TASK_STATE_DATA",
  474. GEARMAN_TASK_STATE_DATA,
  475. CONST_CS | CONST_PERSISTENT);
  476. REGISTER_LONG_CONSTANT("GEARMAN_TASK_STATE_WARNING",
  477. GEARMAN_TASK_STATE_WARNING,
  478. CONST_CS | CONST_PERSISTENT);
  479. REGISTER_LONG_CONSTANT("GEARMAN_TASK_STATE_STATUS",
  480. GEARMAN_TASK_STATE_STATUS,
  481. CONST_CS | CONST_PERSISTENT);
  482. REGISTER_LONG_CONSTANT("GEARMAN_TASK_STATE_COMPLETE",
  483. GEARMAN_TASK_STATE_COMPLETE,
  484. CONST_CS | CONST_PERSISTENT);
  485. REGISTER_LONG_CONSTANT("GEARMAN_TASK_STATE_EXCEPTION",
  486. GEARMAN_TASK_STATE_EXCEPTION,
  487. CONST_CS | CONST_PERSISTENT);
  488. REGISTER_LONG_CONSTANT("GEARMAN_TASK_STATE_FAIL",
  489. GEARMAN_TASK_STATE_FAIL,
  490. CONST_CS | CONST_PERSISTENT);
  491. REGISTER_LONG_CONSTANT("GEARMAN_TASK_STATE_FINISHED",
  492. GEARMAN_TASK_STATE_FINISHED,
  493. CONST_CS | CONST_PERSISTENT);
  494. REGISTER_LONG_CONSTANT("GEARMAN_JOB_PRIORITY_HIGH",
  495. GEARMAN_JOB_PRIORITY_HIGH,
  496. CONST_CS | CONST_PERSISTENT);
  497. REGISTER_LONG_CONSTANT("GEARMAN_JOB_PRIORITY_NORMAL",
  498. GEARMAN_JOB_PRIORITY_NORMAL,
  499. CONST_CS | CONST_PERSISTENT);
  500. REGISTER_LONG_CONSTANT("GEARMAN_JOB_PRIORITY_LOW",
  501. GEARMAN_JOB_PRIORITY_LOW,
  502. CONST_CS | CONST_PERSISTENT);
  503. REGISTER_LONG_CONSTANT("GEARMAN_JOB_PRIORITY_MAX",
  504. GEARMAN_JOB_PRIORITY_MAX,
  505. CONST_CS | CONST_PERSISTENT);
  506. REGISTER_LONG_CONSTANT("GEARMAN_CLIENT_ALLOCATED",
  507. GEARMAN_CLIENT_ALLOCATED,
  508. CONST_CS | CONST_PERSISTENT);
  509. REGISTER_LONG_CONSTANT("GEARMAN_CLIENT_NON_BLOCKING",
  510. GEARMAN_CLIENT_NON_BLOCKING,
  511. CONST_CS | CONST_PERSISTENT);
  512. REGISTER_LONG_CONSTANT("GEARMAN_CLIENT_TASK_IN_USE",
  513. GEARMAN_CLIENT_TASK_IN_USE,
  514. CONST_CS | CONST_PERSISTENT);
  515. REGISTER_LONG_CONSTANT("GEARMAN_CLIENT_UNBUFFERED_RESULT",
  516. GEARMAN_CLIENT_UNBUFFERED_RESULT,
  517. CONST_CS | CONST_PERSISTENT);
  518. REGISTER_LONG_CONSTANT("GEARMAN_CLIENT_NO_NEW",
  519. GEARMAN_CLIENT_NO_NEW,
  520. CONST_CS | CONST_PERSISTENT);
  521. REGISTER_LONG_CONSTANT("GEARMAN_CLIENT_FREE_TASKS",
  522. GEARMAN_CLIENT_FREE_TASKS,
  523. CONST_CS | CONST_PERSISTENT);
  524. REGISTER_LONG_CONSTANT("GEARMAN_CLIENT_STATE_IDLE",
  525. GEARMAN_CLIENT_STATE_IDLE,
  526. CONST_CS | CONST_PERSISTENT);
  527. REGISTER_LONG_CONSTANT("GEARMAN_CLIENT_STATE_NEW",
  528. GEARMAN_CLIENT_STATE_NEW,
  529. CONST_CS | CONST_PERSISTENT);
  530. REGISTER_LONG_CONSTANT("GEARMAN_CLIENT_STATE_SUBMIT",
  531. GEARMAN_CLIENT_STATE_SUBMIT,
  532. CONST_CS | CONST_PERSISTENT);
  533. REGISTER_LONG_CONSTANT("GEARMAN_CLIENT_STATE_PACKET",
  534. GEARMAN_CLIENT_STATE_PACKET,
  535. CONST_CS | CONST_PERSISTENT);
  536. REGISTER_LONG_CONSTANT("GEARMAN_WORKER_ALLOCATED",
  537. GEARMAN_WORKER_ALLOCATED,
  538. CONST_CS | CONST_PERSISTENT);
  539. REGISTER_LONG_CONSTANT("GEARMAN_WORKER_NON_BLOCKING",
  540. GEARMAN_WORKER_NON_BLOCKING,
  541. CONST_CS | CONST_PERSISTENT);
  542. REGISTER_LONG_CONSTANT("GEARMAN_WORKER_PACKET_INIT",
  543. GEARMAN_WORKER_PACKET_INIT,
  544. CONST_CS | CONST_PERSISTENT);
  545. REGISTER_LONG_CONSTANT("GEARMAN_WORKER_GRAB_JOB_IN_USE",
  546. GEARMAN_WORKER_GRAB_JOB_IN_USE,
  547. CONST_CS | CONST_PERSISTENT);
  548. REGISTER_LONG_CONSTANT("GEARMAN_WORKER_PRE_SLEEP_IN_USE",
  549. GEARMAN_WORKER_PRE_SLEEP_IN_USE,
  550. CONST_CS | CONST_PERSISTENT);
  551. REGISTER_LONG_CONSTANT("GEARMAN_WORKER_WORK_JOB_IN_USE",
  552. GEARMAN_WORKER_WORK_JOB_IN_USE,
  553. CONST_CS | CONST_PERSISTENT);
  554. REGISTER_LONG_CONSTANT("GEARMAN_WORKER_CHANGE",
  555. GEARMAN_WORKER_CHANGE,
  556. CONST_CS | CONST_PERSISTENT);
  557. REGISTER_LONG_CONSTANT("GEARMAN_WORKER_GRAB_UNIQ",
  558. GEARMAN_WORKER_GRAB_UNIQ,
  559. CONST_CS | CONST_PERSISTENT);
  560. REGISTER_LONG_CONSTANT("GEARMAN_WORKER_TIMEOUT_RETURN",
  561. GEARMAN_WORKER_TIMEOUT_RETURN,
  562. CONST_CS | CONST_PERSISTENT);
  563. REGISTER_LONG_CONSTANT("GEARMAN_WORKER_STATE_START",
  564. GEARMAN_WORKER_STATE_START,
  565. CONST_CS | CONST_PERSISTENT);
  566. REGISTER_LONG_CONSTANT("GEARMAN_WORKER_STATE_FUNCTION_SEND",
  567. GEARMAN_WORKER_STATE_FUNCTION_SEND,
  568. CONST_CS | CONST_PERSISTENT);
  569. REGISTER_LONG_CONSTANT("GEARMAN_WORKER_STATE_CONNECT",
  570. GEARMAN_WORKER_STATE_CONNECT,
  571. CONST_CS | CONST_PERSISTENT);
  572. REGISTER_LONG_CONSTANT("GEARMAN_WORKER_STATE_GRAB_JOB_SEND",
  573. GEARMAN_WORKER_STATE_GRAB_JOB_SEND,
  574. CONST_CS | CONST_PERSISTENT);
  575. REGISTER_LONG_CONSTANT("GEARMAN_WORKER_STATE_GRAB_JOB_RECV",
  576. GEARMAN_WORKER_STATE_GRAB_JOB_RECV,
  577. CONST_CS | CONST_PERSISTENT);
  578. REGISTER_LONG_CONSTANT("GEARMAN_WORKER_STATE_PRE_SLEEP",
  579. GEARMAN_WORKER_STATE_PRE_SLEEP,
  580. CONST_CS | CONST_PERSISTENT);
  581. /* CONST_GEN_STOP */
  582. return SUCCESS;
  583. }
  584. PHP_MSHUTDOWN_FUNCTION(gearman) {
  585. return SUCCESS;
  586. }
  587. PHP_MINFO_FUNCTION(gearman) {
  588. char port_str[6];
  589. php_info_print_table_start();
  590. php_info_print_table_header(2, "gearman support", "enabled");
  591. php_info_print_table_row(2, "extension version", PHP_GEARMAN_VERSION);
  592. php_info_print_table_row(2, "libgearman version", gearman_version());
  593. php_info_print_table_row(2, "Default TCP Host", GEARMAN_DEFAULT_TCP_HOST);
  594. snprintf(port_str, 6, "%u", GEARMAN_DEFAULT_TCP_PORT);
  595. php_info_print_table_row(2, "Default TCP Port", port_str);
  596. php_info_print_table_end();
  597. }
  598. /* Module config struct. */
  599. zend_module_entry gearman_module_entry = {
  600. STANDARD_MODULE_HEADER,
  601. "gearman",
  602. ext_functions,
  603. PHP_MINIT(gearman),
  604. PHP_MSHUTDOWN(gearman),
  605. NULL,
  606. NULL,
  607. PHP_MINFO(gearman),
  608. PHP_GEARMAN_VERSION,
  609. STANDARD_MODULE_PROPERTIES
  610. };
  611. #ifdef COMPILE_DL_GEARMAN
  612. ZEND_GET_MODULE(gearman)
  613. #endif