Version 4.7.13
This commit is contained in:
1 parent
fd22d99e69
commit
7124a02564
954 files changed
+29277
-59308
No files matched your search
@@ -160,6 +160,10 @@ class _Curl
|
||||
public function __destruct()
|
||||
{
|
||||
curl_close( $this->curl );
|
||||
if( static::$_multiHandle instanceof \CurlMultiHandle )
|
||||
{
|
||||
curl_multi_close( static::$_multiHandle );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -378,6 +382,7 @@ class _Curl
|
||||
/**
|
||||
* Execute the request
|
||||
*
|
||||
* @todo Remove if multi handle works out long term.
|
||||
* @return \IPS\Http\Response
|
||||
* @throws \IPS\Http\Request\CurlException
|
||||
*/
|
||||
@@ -407,6 +412,75 @@ class _Curl
|
||||
/* Return it */
|
||||
return new \IPS\Http\Response( $output );
|
||||
}
|
||||
|
||||
/**
|
||||
* @breif Store the cURL Multi Handle
|
||||
*/
|
||||
protected static $_multiHandle;
|
||||
|
||||
/**
|
||||
* Execute the request via cURL Multi - We use this to cache and share connections between requests
|
||||
*
|
||||
* @return \IPS\Http\Response
|
||||
* @throws \IPS\Http\Request\CurlException
|
||||
*/
|
||||
protected function _executeMh(): \IPS\Http\Response
|
||||
{
|
||||
/* Init multi handle if needed */
|
||||
if( empty( static::$_multiHandle ) )
|
||||
{
|
||||
static::$_multiHandle = curl_multi_init();
|
||||
}
|
||||
|
||||
/* Store handle for this request */
|
||||
curl_multi_add_handle( static::$_multiHandle, $this->curl );
|
||||
|
||||
/* Execute request and wait for response */
|
||||
$active = NULL;
|
||||
do
|
||||
{
|
||||
$ret = curl_multi_exec( static::$_multiHandle, $active );
|
||||
}
|
||||
while( $ret == CURLM_CALL_MULTI_PERFORM );
|
||||
|
||||
while( $active && $ret == CURLM_OK )
|
||||
{
|
||||
if( curl_multi_select( static::$_multiHandle ) != -1 )
|
||||
{
|
||||
do
|
||||
{
|
||||
$mrc = curl_multi_exec( static::$_multiHandle, $active );
|
||||
}
|
||||
while( $mrc == CURLM_CALL_MULTI_PERFORM );
|
||||
}
|
||||
}
|
||||
|
||||
$output = curl_multi_getcontent( $this->curl );
|
||||
|
||||
/* Remove handles we no longer need */
|
||||
curl_multi_remove_handle( static::$_multiHandle, $this->curl );
|
||||
|
||||
/* Log - but because the output can be large, only do this if we explicitly have debug logging enabled */
|
||||
if ( \defined('\IPS\DEBUG_LOG') and \IPS\DEBUG_LOG )
|
||||
{
|
||||
\IPS\Log::debug( "\n\n------------------------------------\ncURL REQUEST: {$this->url}\n------------------------------------\n\n" . implode( "\n", $this->headersForLog ) . "\n\n" . var_export( $this->dataForLog, TRUE ) . "\n\n------------------------------------\nRESPONSE\n------------------------------------\n\n" . $output, 'request' );
|
||||
}
|
||||
|
||||
/* Errors? */
|
||||
if ( $output === FALSE )
|
||||
{
|
||||
throw new CurlException( $this->url . "\n" . curl_error( $this->curl ), curl_errno( $this->curl ) );
|
||||
}
|
||||
|
||||
/* If this is FTP we need to fudge the headers a little */
|
||||
if( isset( $this->url->data['scheme'] ) and $this->url->data['scheme'] == 'ftp' )
|
||||
{
|
||||
$output = "HTTP/1.1 200 OK\nFTP: True\r\n\r\n" . $output;
|
||||
}
|
||||
|
||||
/* Return it */
|
||||
return new \IPS\Http\Response( $output );
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the request and follow redirects id necessary
|
||||
@@ -419,7 +493,7 @@ class _Curl
|
||||
protected function _executeAndFollowRedirects( $method, $params=NULL )
|
||||
{
|
||||
/* Execute */
|
||||
$response = $this->_execute();
|
||||
$response = $this->_executeMh();
|
||||
|
||||
/* Either return it or follow it */
|
||||
if ( $this->followRedirects and \in_array( $response->httpResponseCode, array( 301, 302, 303, 307, 308 ) ) )
|
||||
|
||||
Reference in new issue
Block a user