Revert "Implemented strict http request serialization for APIs that forbid a session to be used in concurrent requests (e.g. dedimania)."

This reverts commit b0732bee96.
Solution required PHP 7.0.7, thus breaking requirement of compatibility with PHP 5.4.
This commit is contained in:
Sebastian Büttner 2017-05-22 22:59:01 +02:00
parent b0732bee96
commit edcd18e8f5
5 changed files with 12 additions and 77 deletions

View File

@ -36,7 +36,6 @@ class AsyncHttpRequest implements UsageInformationAble {
private $contentType = 'text/xml; charset=UTF-8;'; private $contentType = 'text/xml; charset=UTF-8;';
private $timeout = 60; private $timeout = 60;
private $headers = array(); private $headers = array();
private $serialize = false;
public function __construct($maniaControl, $url) { public function __construct($maniaControl, $url) {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
@ -59,7 +58,6 @@ class AsyncHttpRequest implements UsageInformationAble {
->set(CURLOPT_RETURNTRANSFER, true)// ->set(CURLOPT_RETURNTRANSFER, true)//
->set(CURLOPT_FOLLOWLOCATION, true)// support redirect ->set(CURLOPT_FOLLOWLOCATION, true)// support redirect
->set(CURLOPT_SSL_VERIFYPEER, false); ->set(CURLOPT_SSL_VERIFYPEER, false);
$request->setSerialize($this->serialize); // serialize requests to this host
return $request; return $request;
} }
@ -230,13 +228,4 @@ class AsyncHttpRequest implements UsageInformationAble {
public function setTimeout($timeout) { public function setTimeout($timeout) {
$this->timeout = $timeout; $this->timeout = $timeout;
} }
/**
* Sets whether the request to the same host should be serialized.
*
* @param bool $serialize
*/
public function setSerialize($serialize = true) {
$this->serialize = $serialize;
}
} }

View File

@ -23,9 +23,6 @@ class AsynchronousFileReader implements UsageInformationAble {
*/ */
const CONTENT_TYPE_JSON = 'application/json'; const CONTENT_TYPE_JSON = 'application/json';
const QUEUE_NONSERIALIZING = 0;
const QUEUE_SERIALIZING = 1;
/* /*
* Private properties * Private properties
*/ */
@ -33,7 +30,7 @@ class AsynchronousFileReader implements UsageInformationAble {
private $maniaControl = null; private $maniaControl = null;
/** @var \cURL\RequestsQueue|null $requestQueue */ /** @var \cURL\RequestsQueue|null $requestQueue */
private $requestQueue = array(null, null); private $requestQueue = null;
/** /**
* Construct a new Asynchronous File Reader Instance * Construct a new Asynchronous File Reader Instance
@ -42,30 +39,22 @@ class AsynchronousFileReader implements UsageInformationAble {
*/ */
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
$this->requestQueue = new RequestsQueue();
// Queue for non-serializing requests (parallel is preferred)
$this->requestQueue[self::QUEUE_NONSERIALIZING] = new RequestsQueue();
// Queue for per host serialized requests
$this->requestQueue[self::QUEUE_SERIALIZING] = new RequestsQueue();
$this->requestQueue[self::QUEUE_SERIALIZING]->setOption(CURLMOPT_MAX_HOST_CONNECTIONS, 1);
} }
/** /**
* Append available Data of active Requests * Append available Data of active Requests
*/ */
public function appendData() { public function appendData() {
foreach ($this->requestQueue as &$queue) { do {
do { if (($count = $this->requestQueue->count()) == 0) {
if (($count = $queue->count()) == 0) { break;
break; }
}
if ($queue->socketPerform()) { if ($this->requestQueue->socketPerform()) {
$queue->socketSelect(); $this->requestQueue->socketSelect();
} }
} while ($count != $queue->count()); } while ($count != $this->requestQueue->count());
}
} }
/** /**
@ -107,10 +96,6 @@ class AsynchronousFileReader implements UsageInformationAble {
* @param Request $request * @param Request $request
*/ */
public function addRequest(Request $request) { public function addRequest(Request $request) {
$queueId = $request->getSerialize() $request->attachTo($this->requestQueue);
? self::QUEUE_SERIALIZING
: self::QUEUE_NONSERIALIZING;
$queue = $this->requestQueue[$queueId];
$request->attachTo($queue);
} }
} }

View File

@ -20,11 +20,6 @@ class Request extends EventDispatcher implements RequestInterface
*/ */
protected $options = null; protected $options = null;
/**
* @var bool Whether requests to the target host should be serialized or not.
*/
protected $serializeRequests = false;
/** /**
* Create new cURL handle * Create new cURL handle
* *
@ -126,8 +121,7 @@ class Request extends EventDispatcher implements RequestInterface
* @param \cURL\RequestsQueue $requestsQueue * @param \cURL\RequestsQueue $requestsQueue
* @throws \cURL\Exception * @throws \cURL\Exception
*/ */
public function attachTo(RequestsQueue $requestsQueue) public function attachTo(RequestsQueue $requestsQueue) {
{
if (isset($this->queue)) { if (isset($this->queue)) {
throw new Exception('Already bound to a RequestQueue.'); throw new Exception('Already bound to a RequestQueue.');
} }
@ -135,24 +129,6 @@ class Request extends EventDispatcher implements RequestInterface
$this->queue->attach($this); $this->queue->attach($this);
} }
/**
* Whether to serialize requests to the same host or not.
*
* @param bool $serialize
*/
public function setSerialize($serialize = true)
{
$this->serializeRequests = $serialize;
}
/**
* @return bool
*/
public function getSerialize()
{
return $this->serializeRequests;
}
/** /**
* Creates new RequestsQueue with single Request attached to it * Creates new RequestsQueue with single Request attached to it
* and calls RequestsQueue::socketPerform() method. * and calls RequestsQueue::socketPerform() method.

View File

@ -217,12 +217,4 @@ class RequestsQueue extends EventDispatcher implements RequestsQueueInterface, \
} }
return curl_multi_select($this->mh, $timeout) !== -1; return curl_multi_select($this->mh, $timeout) !== -1;
} }
/**
* @param $option
* @param $value
*/
public function setOption($option, $value) {
curl_multi_setopt($this->mh, $option, $value);
}
} }

View File

@ -83,7 +83,6 @@ class DedimaniaWebHandler implements TimerListener {
$asyncHttpRequest->setContent($content); $asyncHttpRequest->setContent($content);
$asyncHttpRequest->setCompression(true); $asyncHttpRequest->setCompression(true);
$asyncHttpRequest->setTimeout(500); $asyncHttpRequest->setTimeout(500);
$asyncHttpRequest->setSerialize();
$asyncHttpRequest->postData(); $asyncHttpRequest->postData();
} }
@ -172,7 +171,6 @@ class DedimaniaWebHandler implements TimerListener {
$asyncHttpRequest->setContent($content); $asyncHttpRequest->setContent($content);
$asyncHttpRequest->setCompression(true); $asyncHttpRequest->setCompression(true);
$asyncHttpRequest->setTimeout(500); $asyncHttpRequest->setTimeout(500);
$asyncHttpRequest->setSerialize();
$asyncHttpRequest->postData(); $asyncHttpRequest->postData();
return true; return true;
@ -220,7 +218,6 @@ class DedimaniaWebHandler implements TimerListener {
$asyncHttpRequest->setContent($content); $asyncHttpRequest->setContent($content);
$asyncHttpRequest->setCompression(true); $asyncHttpRequest->setCompression(true);
$asyncHttpRequest->setTimeout(500); $asyncHttpRequest->setTimeout(500);
$asyncHttpRequest->setSerialize();
$asyncHttpRequest->postData(); $asyncHttpRequest->postData();
} }
@ -312,7 +309,6 @@ class DedimaniaWebHandler implements TimerListener {
$asyncHttpRequest->setContent($content); $asyncHttpRequest->setContent($content);
$asyncHttpRequest->setCompression(false); $asyncHttpRequest->setCompression(false);
$asyncHttpRequest->setTimeout(500); $asyncHttpRequest->setTimeout(500);
$asyncHttpRequest->setSerialize();
$asyncHttpRequest->postData(); $asyncHttpRequest->postData();
} }
@ -365,7 +361,6 @@ class DedimaniaWebHandler implements TimerListener {
$asyncHttpRequest->setContent($content); $asyncHttpRequest->setContent($content);
$asyncHttpRequest->setCompression(true); $asyncHttpRequest->setCompression(true);
$asyncHttpRequest->setTimeout(500); $asyncHttpRequest->setTimeout(500);
$asyncHttpRequest->setSerialize();
$asyncHttpRequest->postData(); $asyncHttpRequest->postData();
} }
@ -408,7 +403,6 @@ class DedimaniaWebHandler implements TimerListener {
$asyncHttpRequest->setContent($content); $asyncHttpRequest->setContent($content);
$asyncHttpRequest->setCompression(true); $asyncHttpRequest->setCompression(true);
$asyncHttpRequest->setTimeout(500); $asyncHttpRequest->setTimeout(500);
$asyncHttpRequest->setSerialize();
$asyncHttpRequest->postData(); $asyncHttpRequest->postData();
} }
@ -453,7 +447,6 @@ class DedimaniaWebHandler implements TimerListener {
$asyncHttpRequest->setContent($content); $asyncHttpRequest->setContent($content);
$asyncHttpRequest->setCompression(true); $asyncHttpRequest->setCompression(true);
$asyncHttpRequest->setTimeout(500); $asyncHttpRequest->setTimeout(500);
$asyncHttpRequest->setSerialize();
$asyncHttpRequest->postData(); $asyncHttpRequest->postData();
} }