summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Flatz2022-03-16 14:32:15 +0100
committerDavid Flatz2022-03-16 15:59:43 +0100
commit7da54466e86cca7f9857f0a9701c95af6c3273a8 (patch)
tree006e8d9f0a0e6d2c6d3d7f248448400139412e86
parent8cd32eecb8a818a1c74232555dbf588a785fe9cd (diff)
downloaditools-7da54466e86cca7f9857f0a9701c95af6c3273a8.tar.gz
itools-7da54466e86cca7f9857f0a9701c95af6c3273a8.tar.bz2
itools-7da54466e86cca7f9857f0a9701c95af6c3273a8.zip
keep CurlHandle and CurlMultiHandle around so that we can profit from connection reuse
-rw-r--r--it_url.class16
1 files changed, 13 insertions, 3 deletions
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 @@
<?php
/*
-** Copyright (C) 1995-2021 by the ITools Authors.
+** Copyright (C) 1995-2022 by the ITools Authors.
** This file is part of ITools - the Internet Tools Library
**
** ITools is free software; you can redistribute it and/or modify
@@ -268,6 +268,7 @@ static function curl_opts($p=array())
function request($p=array())
{
+ static $curl;
$url = $this;
if ($p['url'])
$this->__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) {