summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorSterling Hughes <sterling@php.net>2004-03-12 18:37:55 +0000
committerSterling Hughes <sterling@php.net>2004-03-12 18:37:55 +0000
commit177db33c63de61cb6a29f814e196e5a6469a51b5 (patch)
tree7b7a87f3af7e0482d167ecfd6a513fa3e84571e9 /ext
parent4a31a6a88b96b07d6c3bf015168384e49c0af806 (diff)
downloadphp-git-177db33c63de61cb6a29f814e196e5a6469a51b5.tar.gz
add the curl_copy_handle() function which will exactly duplicate a cURL handle.
Useful when you have multiple "similair" transforms as with a multi handle with only small variances (like the URL)
Diffstat (limited to 'ext')
-rw-r--r--ext/curl/interface.c35
-rw-r--r--ext/curl/php_curl.h1
2 files changed, 36 insertions, 0 deletions
diff --git a/ext/curl/interface.c b/ext/curl/interface.c
index 8674706d67..72a42c6228 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 3e9b9e2cf8..d2a14c43b7 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);