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)
This commit is contained in:
Sterling Hughes 2004-03-12 18:37:55 +00:00
parent 4a31a6a88b
commit 177db33c63
2 changed files with 36 additions and 0 deletions

View File

@ -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)

View File

@ -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);