summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Flatz2022-03-23 14:02:58 +0100
committerDavid Flatz2022-03-23 14:02:58 +0100
commitabb15d8eb591c12d9d71320f4e2b0ce682cd860e (patch)
tree8158d277348ad2caa49ef0bc5f4565a23c6492ca
parentd53b024bb12dcc57fddab168d810a1f8fde4385b (diff)
downloaditools-abb15d8eb591c12d9d71320f4e2b0ce682cd860e.tar.gz
itools-abb15d8eb591c12d9d71320f4e2b0ce682cd860e.tar.bz2
itools-abb15d8eb591c12d9d71320f4e2b0ce682cd860e.zip
make it_url::request and it_url::get_multi fork-safe; this prevents multiple processes from using the same curl handle
-rw-r--r--it_url.class12
1 files changed, 6 insertions, 6 deletions
diff --git a/it_url.class b/it_url.class
index aa2ce4a..cbf390a 100644
--- a/it_url.class
+++ b/it_url.class
@@ -268,7 +268,7 @@ static function curl_opts($p=array())
function request($p=array())
{
- static $curl;
+ static $curl_handles = [];
$url = $this;
if ($p['url'])
$this->__construct($p['url']);
@@ -282,8 +282,8 @@ function request($p=array())
$stderr = it::fopen("php://memory", "r+");
$opts += [CURLOPT_STDERR => $stderr, CURLOPT_VERBOSE => 1];
}
- if (!isset($curl))
- $curl = curl_init($url->url);
+ if (!($curl = $curl_handles[getmypid()]))
+ $curl = $curl_handles[getmypid()] = curl_init($url->url);
else
{
curl_reset($curl);
@@ -380,7 +380,7 @@ function request($p=array())
*/
static function get_multi($p=null)
{
- static $mh;
+ static $curl_multi_handles = [];
$p += array('retries' => 1);
EDC('req', $p);
@@ -390,8 +390,8 @@ static function get_multi($p=null)
$opts = self::curl_opts($p);
- if (!isset($mh))
- $mh = curl_multi_init();
+ if (!($mh = $curl_multi_handles[getmypid()]))
+ $mh = $curl_multi_handles[getmypid()] = curl_multi_init();
$keys = $handles = $urls = $retries = [];
$addhandle = function ($key, $url) use (&$keys, &$handles, &$urls, $opts, $mh) {