Skip to content

Commit

Permalink
Merge pull request #40 from pubnub/develop
Browse files Browse the repository at this point in the history
Version 4.1.4
  • Loading branch information
qsoftdevelopment authored Oct 21, 2019
2 parents 2f7a2af + 7313a17 commit b888899
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 6 deletions.
9 changes: 8 additions & 1 deletion .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
name: php
version: 4.1.3
version: 4.1.4
schema: 1
scm: github.com/pubnub/php
changelog:
- version: 4.1.4
date: Oct 18, 2019
changes:
- type: bug
text: Add support for request transport reusing to resolve slow publish issues when multiple messages are published consecutively.
- type: bug
text: Drop support for HHVM.
- version: 4.1.3
date: Feb 28, 2019
changes:
Expand Down
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ php:
- 5.6
- 7.0
- 7.1
- hhvm
install:
- composer self-update && composer --version
- composer install --prefer-dist
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [v4.1.4](https://github.com/pubnub/php/tree/v4.1.4)
October-18-2019

- 🐛Add support for request transport reusing to resolve slow publish issues when multiple messages are published consecutively.
- 🐛Drop support for HHVM.

## [v4.1.3](https://github.com/pubnub/php/tree/v4.1.3)
February-28-2019

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"keywords": ["api", "real-time", "realtime", "real time", "ajax", "push"],
"homepage": "http://www.pubnub.com/",
"license": "MIT",
"version": "4.1.3",
"version": "4.1.4",
"authors": [
{
"name": "PubNub",
Expand Down
52 changes: 50 additions & 2 deletions src/PubNub/Endpoints/Endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ abstract class Endpoint
/** @var PNEnvelope */
protected $envelope;

/** @var array */
protected static $cachedTransports = [];

public function __construct(PubNub $pubnubInstance)
{
$this->pubnub = $pubnubInstance;
Expand Down Expand Up @@ -275,7 +278,8 @@ protected function invokeRequestAndCacheIt()
protected function requestOptions() {
$options = [
'timeout' => $this->getRequestTimeout(),
'connect_timeout' => $this->getConnectTimeout()
'connect_timeout' => $this->getConnectTimeout(),
'transport' => $this->getDefaultTransport()
];

$transport = $this->pubnub->getConfiguration()->getTransport();
Expand All @@ -292,7 +296,7 @@ protected function requestOptions() {
*/
protected function invokeRequest()
{
$headers = ['Accept' => 'application/json'];
$headers = ['Accept' => 'application/json', 'Connection' => 'Keep-Alive'];

$url = PubNubUtil::buildUrl(
$this->pubnub->getBasePath(),
Expand Down Expand Up @@ -509,6 +513,50 @@ protected function getAffectedChannelGroups()
return null;
}

/**
* @return \Requests_Transport
* @throws \Exception
*/
private function getDefaultTransport()
{
$need_ssl = (0 === stripos($this->pubnub->getBasePath(), 'https://'));
$capabilities = array('ssl' => $need_ssl);

$cap_string = serialize($capabilities);
$method = $this->httpMethod();

if(!isset(self::$cachedTransports[$method])) {
self::$cachedTransports[$method] = [];
}

if (isset(self::$cachedTransports[$method][$cap_string]) && self::$cachedTransports[$method][$cap_string] !== null) {
return self::$cachedTransports[$method][$cap_string];
}

$transports = array(
'Requests_Transport_cURL',
'Requests_Transport_fsockopen',
);

foreach ($transports as $class) {
if (!class_exists($class)) {
continue;
}

$result = call_user_func(array($class, 'test'), $capabilities);
if ($result) {
self::$cachedTransports[$method][$cap_string] = new $class();
break;
}
}

if(self::$cachedTransports[$method][$cap_string] === null) {
throw new \Exception('No working transports found');
}

return self::$cachedTransports[$method][$cap_string];
}

/**
* @param $json
* @return array
Expand Down
2 changes: 1 addition & 1 deletion src/PubNub/PubNub.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

class PubNub
{
const SDK_VERSION = "4.1.3";
const SDK_VERSION = "4.1.4";
const SDK_NAME = "PubNub-PHP";

public static $MAX_SEQUENCE = 65535;
Expand Down

0 comments on commit b888899

Please sign in to comment.