diff --git a/ext/curl/interface.c b/ext/curl/interface.c index 8674706d67f..72a42c6228e 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -59,6 +59,7 @@ static void _php_curl_close(zend_rsrc_list_entry *rsrc TSRMLS_DC); */ function_entry curl_functions[] = { PHP_FE(curl_init, NULL) + PHP_FE(curl_copy_handle, NULL) PHP_FE(curl_version, NULL) PHP_FE(curl_setopt, NULL) PHP_FE(curl_exec, NULL) @@ -780,6 +781,40 @@ PHP_FUNCTION(curl_init) } /* }}} */ +/* {{{ proto resource curl_copy_handle(resource ch) + Copy a cURL handle along with all of it's preferences */ +PHP_FUNCTION(curl_copy_handle) +{ + zval *zid; + CURL *cp; + php_curl *ch; + php_curl *dupch; + + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &zid) == FAILURE) { + WRONG_PARAM_COUNT; + } + ZEND_FETCH_RESOURCE(ch, php_curl *, zid, -1, le_curl_name, le_curl); + + cp = curl_easy_duphandle(ch->cp); + if (!cp) { + php_error(E_WARNING, "Cannot duplicate cURL handle"); + RETURN_FALSE; + } + + alloc_curl_handle(&dupch); + TSRMLS_SET_CTX(ch->thread_ctx); + + dupch->cp = cp; + dupch->handlers->write->method = ch->handlers->write->method; + dupch->handlers->write->type = ch->handlers->write->type; + dupch->handlers->read->method = ch->handlers->read->method; + dupch->handlers->write_header->method = ch->handlers->write_header->method; + + ZEND_REGISTER_RESOURCE(return_value, dupch, le_curl); + dupch->id = Z_LVAL_P(return_value); +} +/* }}} */ + /* {{{ proto bool curl_setopt(resource ch, string option, mixed value) Set an option for a CURL transfer */ PHP_FUNCTION(curl_setopt) diff --git a/ext/curl/php_curl.h b/ext/curl/php_curl.h index 3e9b9e2cf8d..d2a14c43b7e 100644 --- a/ext/curl/php_curl.h +++ b/ext/curl/php_curl.h @@ -61,6 +61,7 @@ PHP_MSHUTDOWN_FUNCTION(curl); PHP_MINFO_FUNCTION(curl); PHP_FUNCTION(curl_version); PHP_FUNCTION(curl_init); +PHP_FUNCTION(curl_copy_handle); PHP_FUNCTION(curl_setopt); PHP_FUNCTION(curl_exec); PHP_FUNCTION(curl_getinfo);