multi.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 7 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2018 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Author: Sterling Hughes <sterling@php.net> |
  16. +----------------------------------------------------------------------+
  17. */
  18. #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
  19. #ifdef HAVE_CONFIG_H
  20. #include "config.h"
  21. #endif
  22. #include "php.h"
  23. #if HAVE_CURL
  24. #include "php_curl.h"
  25. #include <curl/curl.h>
  26. #include <curl/multi.h>
  27. #ifdef HAVE_SYS_SELECT_H
  28. #include <sys/select.h>
  29. #endif
  30. #ifdef HAVE_SYS_TIME_H
  31. #include <sys/time.h>
  32. #endif
  33. #ifdef HAVE_SYS_TYPES_H
  34. #include <sys/types.h>
  35. #endif
  36. #ifdef HAVE_UNISTD_H
  37. #include <unistd.h>
  38. #endif
  39. #define SAVE_CURLM_ERROR(__handle, __err) (__handle)->err.no = (int) __err;
  40. /* {{{ proto resource curl_multi_init(void)
  41. Returns a new cURL multi handle */
  42. PHP_FUNCTION(curl_multi_init)
  43. {
  44. php_curlm *mh;
  45. if (zend_parse_parameters_none() == FAILURE) {
  46. return;
  47. }
  48. mh = ecalloc(1, sizeof(php_curlm));
  49. mh->multi = curl_multi_init();
  50. mh->handlers = ecalloc(1, sizeof(php_curlm_handlers));
  51. zend_llist_init(&mh->easyh, sizeof(zval), _php_curl_multi_cleanup_list, 0);
  52. RETURN_RES(zend_register_resource(mh, le_curl_multi_handle));
  53. }
  54. /* }}} */
  55. /* {{{ proto int curl_multi_add_handle(resource mh, resource ch)
  56. Add a normal cURL handle to a cURL multi handle */
  57. PHP_FUNCTION(curl_multi_add_handle)
  58. {
  59. zval *z_mh;
  60. zval *z_ch;
  61. php_curlm *mh;
  62. php_curl *ch;
  63. CURLMcode error = CURLM_OK;
  64. ZEND_PARSE_PARAMETERS_START(2,2)
  65. Z_PARAM_RESOURCE(z_mh)
  66. Z_PARAM_RESOURCE(z_ch)
  67. ZEND_PARSE_PARAMETERS_END();
  68. if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
  69. RETURN_FALSE;
  70. }
  71. if ((ch = (php_curl *)zend_fetch_resource(Z_RES_P(z_ch), le_curl_name, le_curl)) == NULL) {
  72. RETURN_FALSE;
  73. }
  74. _php_curl_verify_handlers(ch, 1);
  75. _php_curl_cleanup_handle(ch);
  76. GC_ADDREF(Z_RES_P(z_ch));
  77. zend_llist_add_element(&mh->easyh, z_ch);
  78. error = curl_multi_add_handle(mh->multi, ch->cp);
  79. SAVE_CURLM_ERROR(mh, error);
  80. RETURN_LONG((zend_long) error);
  81. }
  82. /* }}} */
  83. void _php_curl_multi_cleanup_list(void *data) /* {{{ */
  84. {
  85. zval *z_ch = (zval *)data;
  86. php_curl *ch;
  87. if (!z_ch) {
  88. return;
  89. }
  90. if (!Z_RES_P(z_ch)->ptr) {
  91. return;
  92. }
  93. if ((ch = (php_curl *)zend_fetch_resource(Z_RES_P(z_ch), le_curl_name, le_curl)) == NULL) {
  94. return;
  95. }
  96. zend_list_delete(Z_RES_P(z_ch));
  97. }
  98. /* }}} */
  99. /* Used internally as comparison routine passed to zend_list_del_element */
  100. static int curl_compare_resources( zval *z1, zval *z2 ) /* {{{ */
  101. {
  102. return (Z_TYPE_P(z1) == Z_TYPE_P(z2) &&
  103. Z_TYPE_P(z1) == IS_RESOURCE &&
  104. Z_RES_P(z1) == Z_RES_P(z2));
  105. }
  106. /* }}} */
  107. /* Used to find the php_curl resource for a given curl easy handle */
  108. static zval *_php_curl_multi_find_easy_handle(php_curlm *mh, CURL *easy) /* {{{ */
  109. {
  110. php_curl *tmp_ch;
  111. zend_llist_position pos;
  112. zval *pz_ch_temp;
  113. for(pz_ch_temp = (zval *)zend_llist_get_first_ex(&mh->easyh, &pos); pz_ch_temp;
  114. pz_ch_temp = (zval *)zend_llist_get_next_ex(&mh->easyh, &pos)) {
  115. if ((tmp_ch = (php_curl *)zend_fetch_resource(Z_RES_P(pz_ch_temp), le_curl_name, le_curl)) == NULL) {
  116. return NULL;
  117. }
  118. if (tmp_ch->cp == easy) {
  119. return pz_ch_temp;
  120. }
  121. }
  122. return NULL;
  123. }
  124. /* }}} */
  125. /* {{{ proto int curl_multi_remove_handle(resource mh, resource ch)
  126. Remove a multi handle from a set of cURL handles */
  127. PHP_FUNCTION(curl_multi_remove_handle)
  128. {
  129. zval *z_mh;
  130. zval *z_ch;
  131. php_curlm *mh;
  132. php_curl *ch;
  133. CURLMcode error = CURLM_OK;
  134. ZEND_PARSE_PARAMETERS_START(2,2)
  135. Z_PARAM_RESOURCE(z_mh)
  136. Z_PARAM_RESOURCE(z_ch)
  137. ZEND_PARSE_PARAMETERS_END();
  138. if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
  139. RETURN_FALSE;
  140. }
  141. if ((ch = (php_curl *)zend_fetch_resource(Z_RES_P(z_ch), le_curl_name, le_curl)) == NULL) {
  142. RETURN_FALSE;
  143. }
  144. error = curl_multi_remove_handle(mh->multi, ch->cp);
  145. SAVE_CURLM_ERROR(mh, error);
  146. RETVAL_LONG((zend_long) error);
  147. zend_llist_del_element(&mh->easyh, z_ch, (int (*)(void *, void *))curl_compare_resources);
  148. }
  149. /* }}} */
  150. #if LIBCURL_VERSION_NUM < 0x071c00
  151. static void _make_timeval_struct(struct timeval *to, double timeout) /* {{{ */
  152. {
  153. unsigned long conv;
  154. conv = (unsigned long) (timeout * 1000000.0);
  155. to->tv_sec = conv / 1000000;
  156. to->tv_usec = conv % 1000000;
  157. }
  158. /* }}} */
  159. #endif
  160. /* {{{ proto int curl_multi_select(resource mh[, double timeout])
  161. Get all the sockets associated with the cURL extension, which can then be "selected" */
  162. PHP_FUNCTION(curl_multi_select)
  163. {
  164. zval *z_mh;
  165. php_curlm *mh;
  166. double timeout = 1.0;
  167. #if LIBCURL_VERSION_NUM >= 0x071c00 /* Available since 7.28.0 */
  168. int numfds = 0;
  169. #else
  170. fd_set readfds;
  171. fd_set writefds;
  172. fd_set exceptfds;
  173. int maxfd;
  174. struct timeval to;
  175. #endif
  176. CURLMcode error = CURLM_OK;
  177. ZEND_PARSE_PARAMETERS_START(1,2)
  178. Z_PARAM_RESOURCE(z_mh)
  179. Z_PARAM_OPTIONAL
  180. Z_PARAM_DOUBLE(timeout)
  181. ZEND_PARSE_PARAMETERS_END();
  182. if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
  183. RETURN_FALSE;
  184. }
  185. #if LIBCURL_VERSION_NUM >= 0x071c00 /* Available since 7.28.0 */
  186. error = curl_multi_wait(mh->multi, NULL, 0, (unsigned long) (timeout * 1000.0), &numfds);
  187. if (CURLM_OK != error) {
  188. SAVE_CURLM_ERROR(mh, error);
  189. RETURN_LONG(-1);
  190. }
  191. RETURN_LONG(numfds);
  192. #else
  193. _make_timeval_struct(&to, timeout);
  194. FD_ZERO(&readfds);
  195. FD_ZERO(&writefds);
  196. FD_ZERO(&exceptfds);
  197. error = curl_multi_fdset(mh->multi, &readfds, &writefds, &exceptfds, &maxfd);
  198. SAVE_CURLM_ERROR(mh, error);
  199. if (maxfd == -1) {
  200. RETURN_LONG(-1);
  201. }
  202. RETURN_LONG(select(maxfd + 1, &readfds, &writefds, &exceptfds, &to));
  203. #endif
  204. }
  205. /* }}} */
  206. /* {{{ proto int curl_multi_exec(resource mh, int &still_running)
  207. Run the sub-connections of the current cURL handle */
  208. PHP_FUNCTION(curl_multi_exec)
  209. {
  210. zval *z_mh;
  211. zval *z_still_running;
  212. php_curlm *mh;
  213. int still_running;
  214. CURLMcode error = CURLM_OK;
  215. ZEND_PARSE_PARAMETERS_START(2, 2)
  216. Z_PARAM_RESOURCE(z_mh)
  217. Z_PARAM_ZVAL_DEREF(z_still_running)
  218. ZEND_PARSE_PARAMETERS_END();
  219. if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
  220. RETURN_FALSE;
  221. }
  222. {
  223. zend_llist_position pos;
  224. php_curl *ch;
  225. zval *pz_ch;
  226. for (pz_ch = (zval *)zend_llist_get_first_ex(&mh->easyh, &pos); pz_ch;
  227. pz_ch = (zval *)zend_llist_get_next_ex(&mh->easyh, &pos)) {
  228. if ((ch = (php_curl *)zend_fetch_resource(Z_RES_P(pz_ch), le_curl_name, le_curl)) == NULL) {
  229. RETURN_FALSE;
  230. }
  231. _php_curl_verify_handlers(ch, 1);
  232. }
  233. }
  234. still_running = zval_get_long(z_still_running);
  235. error = curl_multi_perform(mh->multi, &still_running);
  236. zval_ptr_dtor(z_still_running);
  237. ZVAL_LONG(z_still_running, still_running);
  238. SAVE_CURLM_ERROR(mh, error);
  239. RETURN_LONG((zend_long) error);
  240. }
  241. /* }}} */
  242. /* {{{ proto string curl_multi_getcontent(resource ch)
  243. Return the content of a cURL handle if CURLOPT_RETURNTRANSFER is set */
  244. PHP_FUNCTION(curl_multi_getcontent)
  245. {
  246. zval *z_ch;
  247. php_curl *ch;
  248. ZEND_PARSE_PARAMETERS_START(1,1)
  249. Z_PARAM_RESOURCE(z_ch)
  250. ZEND_PARSE_PARAMETERS_END();
  251. if ((ch = (php_curl *)zend_fetch_resource(Z_RES_P(z_ch), le_curl_name, le_curl)) == NULL) {
  252. RETURN_FALSE;
  253. }
  254. if (ch->handlers->write->method == PHP_CURL_RETURN) {
  255. if (!ch->handlers->write->buf.s) {
  256. RETURN_EMPTY_STRING();
  257. }
  258. smart_str_0(&ch->handlers->write->buf);
  259. RETURN_STR_COPY(ch->handlers->write->buf.s);
  260. }
  261. RETURN_NULL();
  262. }
  263. /* }}} */
  264. /* {{{ proto array curl_multi_info_read(resource mh [, int &msgs_in_queue])
  265. Get information about the current transfers */
  266. PHP_FUNCTION(curl_multi_info_read)
  267. {
  268. zval *z_mh;
  269. php_curlm *mh;
  270. CURLMsg *tmp_msg;
  271. int queued_msgs;
  272. zval *zmsgs_in_queue = NULL;
  273. php_curl *ch;
  274. ZEND_PARSE_PARAMETERS_START(1, 2)
  275. Z_PARAM_RESOURCE(z_mh)
  276. Z_PARAM_OPTIONAL
  277. Z_PARAM_ZVAL_DEREF(zmsgs_in_queue)
  278. ZEND_PARSE_PARAMETERS_END();
  279. if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
  280. RETURN_FALSE;
  281. }
  282. tmp_msg = curl_multi_info_read(mh->multi, &queued_msgs);
  283. if (tmp_msg == NULL) {
  284. RETURN_FALSE;
  285. }
  286. if (zmsgs_in_queue) {
  287. zval_ptr_dtor(zmsgs_in_queue);
  288. ZVAL_LONG(zmsgs_in_queue, queued_msgs);
  289. }
  290. array_init(return_value);
  291. add_assoc_long(return_value, "msg", tmp_msg->msg);
  292. add_assoc_long(return_value, "result", tmp_msg->data.result);
  293. /* find the original easy curl handle */
  294. {
  295. zval *pz_ch = _php_curl_multi_find_easy_handle(mh, tmp_msg->easy_handle);
  296. if (pz_ch != NULL) {
  297. /* we are adding a reference to the underlying php_curl
  298. resource, so we need to add one to the resource's refcount
  299. in order to ensure it doesn't get destroyed when the
  300. underlying curl easy handle goes out of scope.
  301. Normally you would call zval_copy_ctor( pz_ch ), or
  302. SEPARATE_ZVAL, but those create new zvals, which is already
  303. being done in add_assoc_resource */
  304. Z_ADDREF_P(pz_ch);
  305. /* we must save result to be able to read error message */
  306. ch = (php_curl*)zend_fetch_resource(Z_RES_P(pz_ch), le_curl_name, le_curl);
  307. SAVE_CURL_ERROR(ch, tmp_msg->data.result);
  308. /* add_assoc_resource automatically creates a new zval to
  309. wrap the "resource" represented by the current pz_ch */
  310. add_assoc_zval(return_value, "handle", pz_ch);
  311. }
  312. }
  313. }
  314. /* }}} */
  315. /* {{{ proto void curl_multi_close(resource mh)
  316. Close a set of cURL handles */
  317. PHP_FUNCTION(curl_multi_close)
  318. {
  319. zval *z_mh;
  320. php_curlm *mh;
  321. ZEND_PARSE_PARAMETERS_START(1,1)
  322. Z_PARAM_RESOURCE(z_mh)
  323. ZEND_PARSE_PARAMETERS_END();
  324. if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
  325. RETURN_FALSE;
  326. }
  327. zend_list_close(Z_RES_P(z_mh));
  328. }
  329. /* }}} */
  330. void _php_curl_multi_close(zend_resource *rsrc) /* {{{ */
  331. {
  332. php_curlm *mh = (php_curlm *)rsrc->ptr;
  333. if (mh) {
  334. zend_llist_position pos;
  335. php_curl *ch;
  336. zval *pz_ch;
  337. for (pz_ch = (zval *)zend_llist_get_first_ex(&mh->easyh, &pos); pz_ch;
  338. pz_ch = (zval *)zend_llist_get_next_ex(&mh->easyh, &pos)) {
  339. /* ptr is NULL means it already be freed */
  340. if (Z_RES_P(pz_ch)->ptr) {
  341. if ((ch = (php_curl *) zend_fetch_resource(Z_RES_P(pz_ch), le_curl_name, le_curl))) {
  342. _php_curl_verify_handlers(ch, 0);
  343. }
  344. }
  345. }
  346. curl_multi_cleanup(mh->multi);
  347. zend_llist_clean(&mh->easyh);
  348. if (mh->handlers->server_push) {
  349. zval_ptr_dtor(&mh->handlers->server_push->func_name);
  350. efree(mh->handlers->server_push);
  351. }
  352. if (mh->handlers) {
  353. efree(mh->handlers);
  354. }
  355. efree(mh);
  356. rsrc->ptr = NULL;
  357. }
  358. }
  359. /* }}} */
  360. /* {{{ proto int curl_multi_errno(resource mh)
  361. Return an integer containing the last multi curl error number */
  362. PHP_FUNCTION(curl_multi_errno)
  363. {
  364. zval *z_mh;
  365. php_curlm *mh;
  366. ZEND_PARSE_PARAMETERS_START(1,1)
  367. Z_PARAM_RESOURCE(z_mh)
  368. ZEND_PARSE_PARAMETERS_END();
  369. if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
  370. RETURN_FALSE;
  371. }
  372. RETURN_LONG(mh->err.no);
  373. }
  374. /* }}} */
  375. /* {{{ proto bool curl_multi_strerror(int code)
  376. return string describing error code */
  377. PHP_FUNCTION(curl_multi_strerror)
  378. {
  379. zend_long code;
  380. const char *str;
  381. ZEND_PARSE_PARAMETERS_START(1,1)
  382. Z_PARAM_LONG(code)
  383. ZEND_PARSE_PARAMETERS_END();
  384. str = curl_multi_strerror(code);
  385. if (str) {
  386. RETURN_STRING(str);
  387. } else {
  388. RETURN_NULL();
  389. }
  390. }
  391. /* }}} */
  392. #if LIBCURL_VERSION_NUM >= 0x072C00 /* Available since 7.44.0 */
  393. static int _php_server_push_callback(CURL *parent_ch, CURL *easy, size_t num_headers, struct curl_pushheaders *push_headers, void *userp) /* {{{ */
  394. {
  395. php_curl *ch;
  396. php_curl *parent;
  397. php_curlm *mh = (php_curlm *)userp;
  398. size_t rval = CURL_PUSH_DENY;
  399. php_curlm_server_push *t = mh->handlers->server_push;
  400. zval *pz_parent_ch = NULL;
  401. zval pz_ch;
  402. zval headers;
  403. zval retval;
  404. zend_resource *res;
  405. char *header;
  406. int error;
  407. zend_fcall_info fci = empty_fcall_info;
  408. pz_parent_ch = _php_curl_multi_find_easy_handle(mh, parent_ch);
  409. if (pz_parent_ch == NULL) {
  410. return rval;
  411. }
  412. parent = (php_curl*)zend_fetch_resource(Z_RES_P(pz_parent_ch), le_curl_name, le_curl);
  413. ch = alloc_curl_handle();
  414. ch->cp = easy;
  415. _php_setup_easy_copy_handlers(ch, parent);
  416. Z_ADDREF_P(pz_parent_ch);
  417. res = zend_register_resource(ch, le_curl);
  418. ch->res = res;
  419. ZVAL_RES(&pz_ch, res);
  420. size_t i;
  421. array_init(&headers);
  422. for(i=0; i<num_headers; i++) {
  423. header = curl_pushheader_bynum(push_headers, i);
  424. add_next_index_string(&headers, header);
  425. }
  426. zend_fcall_info_init(&t->func_name, 0, &fci, &t->fci_cache, NULL, NULL);
  427. zend_fcall_info_argn(
  428. &fci, 3,
  429. pz_parent_ch,
  430. &pz_ch,
  431. &headers
  432. );
  433. fci.retval = &retval;
  434. error = zend_call_function(&fci, &t->fci_cache);
  435. zend_fcall_info_args_clear(&fci, 1);
  436. zval_ptr_dtor_nogc(&headers);
  437. if (error == FAILURE) {
  438. php_error_docref(NULL, E_WARNING, "Cannot call the CURLMOPT_PUSHFUNCTION");
  439. } else if (!Z_ISUNDEF(retval)) {
  440. if (CURL_PUSH_DENY != zval_get_long(&retval)) {
  441. rval = CURL_PUSH_OK;
  442. GC_ADDREF(Z_RES(pz_ch));
  443. zend_llist_add_element(&mh->easyh, &pz_ch);
  444. } else {
  445. /* libcurl will free this easy handle, avoid double free */
  446. ch->cp = NULL;
  447. }
  448. }
  449. return rval;
  450. }
  451. /* }}} */
  452. #endif
  453. static int _php_curl_multi_setopt(php_curlm *mh, zend_long option, zval *zvalue, zval *return_value) /* {{{ */
  454. {
  455. CURLMcode error = CURLM_OK;
  456. switch (option) {
  457. #if LIBCURL_VERSION_NUM >= 0x071000 /* 7.16.0 */
  458. case CURLMOPT_PIPELINING:
  459. #endif
  460. #if LIBCURL_VERSION_NUM >= 0x071003 /* 7.16.3 */
  461. case CURLMOPT_MAXCONNECTS:
  462. #endif
  463. #if LIBCURL_VERSION_NUM >= 0x071e00 /* 7.30.0 */
  464. case CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE:
  465. case CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE:
  466. case CURLMOPT_MAX_HOST_CONNECTIONS:
  467. case CURLMOPT_MAX_PIPELINE_LENGTH:
  468. case CURLMOPT_MAX_TOTAL_CONNECTIONS:
  469. #endif
  470. error = curl_multi_setopt(mh->multi, option, zval_get_long(zvalue));
  471. break;
  472. #if LIBCURL_VERSION_NUM > 0x072D00 /* Available since 7.46.0 */
  473. case CURLMOPT_PUSHFUNCTION:
  474. if (mh->handlers->server_push == NULL) {
  475. mh->handlers->server_push = ecalloc(1, sizeof(php_curlm_server_push));
  476. } else if (!Z_ISUNDEF(mh->handlers->server_push->func_name)) {
  477. zval_ptr_dtor(&mh->handlers->server_push->func_name);
  478. mh->handlers->server_push->fci_cache = empty_fcall_info_cache;
  479. }
  480. ZVAL_COPY(&mh->handlers->server_push->func_name, zvalue);
  481. mh->handlers->server_push->method = PHP_CURL_USER;
  482. error = curl_multi_setopt(mh->multi, option, _php_server_push_callback);
  483. if (error != CURLM_OK) {
  484. return 0;
  485. }
  486. error = curl_multi_setopt(mh->multi, CURLMOPT_PUSHDATA, mh);
  487. break;
  488. #endif
  489. default:
  490. php_error_docref(NULL, E_WARNING, "Invalid curl multi configuration option");
  491. error = CURLM_UNKNOWN_OPTION;
  492. break;
  493. }
  494. SAVE_CURLM_ERROR(mh, error);
  495. if (error != CURLM_OK) {
  496. return 1;
  497. } else {
  498. return 0;
  499. }
  500. }
  501. /* }}} */
  502. /* {{{ proto int curl_multi_setopt(resource mh, int option, mixed value)
  503. Set an option for the curl multi handle */
  504. PHP_FUNCTION(curl_multi_setopt)
  505. {
  506. zval *z_mh, *zvalue;
  507. zend_long options;
  508. php_curlm *mh;
  509. ZEND_PARSE_PARAMETERS_START(3,3)
  510. Z_PARAM_RESOURCE(z_mh)
  511. Z_PARAM_LONG(options)
  512. Z_PARAM_ZVAL(zvalue)
  513. ZEND_PARSE_PARAMETERS_END();
  514. if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
  515. RETURN_FALSE;
  516. }
  517. if (!_php_curl_multi_setopt(mh, options, zvalue, return_value)) {
  518. RETURN_TRUE;
  519. } else {
  520. RETURN_FALSE;
  521. }
  522. }
  523. /* }}} */
  524. #endif
  525. /*
  526. * Local variables:
  527. * tab-width: 4
  528. * c-basic-offset: 4
  529. * End:
  530. * vim600: noet sw=4 ts=4 fdm=marker
  531. * vim<600: noet sw=4 ts=4
  532. */