From 7da54466e86cca7f9857f0a9701c95af6c3273a8 Mon Sep 17 00:00:00 2001 From: David Flatz Date: Wed, 16 Mar 2022 14:32:15 +0100 Subject: keep CurlHandle and CurlMultiHandle around so that we can profit from connection reuse --- it_url.class | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'it_url.class') diff --git a/it_url.class b/it_url.class index 0e81354..aa2ce4a 100644 --- a/it_url.class +++ b/it_url.class @@ -1,6 +1,6 @@ __construct($p['url']); @@ -281,7 +282,14 @@ function request($p=array()) $stderr = it::fopen("php://memory", "r+"); $opts += [CURLOPT_STDERR => $stderr, CURLOPT_VERBOSE => 1]; } - $curl = curl_init($url->url); + if (!isset($curl)) + $curl = curl_init($url->url); + else + { + curl_reset($curl); + curl_setopt($curl, CURLOPT_URL, $url->url); + } + if ($p['maxlength'] && !$p['writefunction']) { @@ -372,6 +380,7 @@ function request($p=array()) */ static function get_multi($p=null) { + static $mh; $p += array('retries' => 1); EDC('req', $p); @@ -381,7 +390,8 @@ static function get_multi($p=null) $opts = self::curl_opts($p); - $mh = curl_multi_init(); + if (!isset($mh)) + $mh = curl_multi_init(); $keys = $handles = $urls = $retries = []; $addhandle = function ($key, $url) use (&$keys, &$handles, &$urls, $opts, $mh) { -- cgit v1.2.3