Skip to content

Commit 1a5d9d7

Browse files
author
Jon Elverkilde
authored
Merge pull request #289 from pusher/guzzle
Switch to Guzzle for HTTP calls
2 parents 1024077 + ba469c7 commit 1a5d9d7

20 files changed

+289
-508
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
php: [7.1, 7.2, 7.3, 7.4, 8.0]
14+
php: [7.2, 7.3, 7.4, 8.0]
1515
stability: [prefer-lowest, prefer-stable]
1616

1717
name: PHP ${{ matrix.php }} - ${{ matrix.stability }} Test

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
## 6.0.0
4+
5+
* [CHANGED] internal HTTP client to Guzzle
6+
* [ADDED] optional client parameter to constructor
7+
* [CHANGED] useTLS is true by default
8+
* [REMOVED] from options
9+
* [REMOVED] customer logger
10+
* [REMOVED] host, port and timeout constructor parameters
11+
* [REMOVED] support for PHP 7.1
12+
* [CHANGED] lower severity level of logging to DEBUG level
13+
314
## 5.0.3
415

516
* [CHANGED] Ensure version in Pusher.php is bumped on release.

README.md

Lines changed: 45 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,16 @@ Or add to `composer.json`:
1818

1919
```json
2020
"require": {
21-
"pusher/pusher-php-server": "^5.0"
21+
"pusher/pusher-php-server": "^6.0"
2222
}
2323
```
2424

2525
and then run `composer update`.
2626

27-
Or you can clone or download the library files.
28-
29-
**We recommend you [use composer](http://getcomposer.org/).**
30-
31-
This library depends on PHP modules for cURL and JSON. See [cURL module installation instructions](http://php.net/manual/en/curl.installation.php) and [JSON module installation instructions](http://php.net/manual/en/json.installation.php).
32-
3327
## Supported platforms
3428

35-
* PHP - supports PHP versions 7.1, 7.2, 7.3, 7.4 and 8.0.
36-
* Laravel - version 5.3 and above has built-in support for Pusher Channels as a [Broadcasting backend](https://laravel.com/docs/master/broadcasting).
29+
* PHP - supports PHP versions 7.2, 7.3, 7.4 and 8.0.
30+
* Laravel - version 8.29 and above has built-in support for Pusher Channels as a [Broadcasting backend](https://laravel.com/docs/master/broadcasting).
3731
* Other PHP frameworks - supported provided you are using a supported version of PHP.
3832

3933
## Pusher Channels constructor
@@ -60,46 +54,23 @@ The fourth parameter is an `$options` array. The additional options are:
6054
* `timeout` - the HTTP timeout
6155
* `useTLS` - quick option to use scheme of https and port 443.
6256
* `cluster` - specify the cluster where the application is running from.
63-
* `curl_options` - array with custom curl commands
6457
* `encryption_master_key` - a 32 char long key. This key, along with the
6558
channel name, are used to derive per-channel encryption keys. Per-channel
6659
keys are used encrypt event data on encrypted channels.
6760

68-
For example, by default calls will be made over a non-TLS connection. To change
69-
this to make calls over HTTPS use:
61+
For example, by default calls will be made over HTTPS. To use plain
62+
HTTP you can set useTLS to false:
7063

7164
```php
72-
$pusher = new Pusher\Pusher( $app_key, $app_secret, $app_id, array( 'cluster' => $app_cluster, 'useTLS' => true ) );
73-
```
74-
75-
For example, if you want to set custom curl options, use this:
76-
77-
```php
78-
$pusher = new Pusher\Pusher(
79-
$app_key,
80-
$app_secret,
81-
$app_id,
82-
array(
83-
'cluster' => $app_cluster,
84-
'useTLS' => true,
85-
'curl_options' => array( CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4 )
86-
)
87-
);
65+
$options = [
66+
'cluster' => $app_cluster,
67+
'useTLS' => false
68+
];
69+
$pusher = new Pusher\Pusher( $app_key, $app_secret, $app_id, $options );
8870
```
8971

90-
**Note**: The `host` option overrides the `cluster` option!
91-
92-
**Note:** The `$options` parameter was introduced in version 2.2.0 of the
93-
library. Previously additional parameters could be passed for each option, but
94-
this was becoming unwieldy. However, backwards compatibility has been
95-
maintained.
96-
9772
## Logging configuration
9873

99-
It is strongly recommended that you configure a logger.
100-
101-
### PSR-3 Support
102-
10374
The recommended approach of logging is to use a
10475
[PSR-3](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md)
10576
compliant logger implementing `Psr\Log\LoggerInterface`. The `Pusher` object
@@ -112,28 +83,26 @@ implements `Psr\Log\LoggerAwareInterface`, meaning you call
11283
$pusher->setLogger($logger);
11384
```
11485

115-
### Custom Logger (deprecated)
116-
117-
> **Warning**: Using `Pusher::set_logger()` and a custom object implementing
118-
> `log()` is now deprecated and will be removed in the future. Please use a
119-
> PSR-3 compliant logger.
86+
## Custom Guzzle client
12087

121-
You set up logging by passing an object with a `log` function to the
122-
`pusher->set_logger` function:
88+
This library uses Guzzle internally to make HTTP calls. You can pass
89+
your own Guzzle instance to the Pusher constructor:
12390

12491
```php
125-
class MyLogger {
126-
public function log( $msg ) {
127-
print_r( $msg . "\n" );
128-
}
129-
}
92+
$custom_client = new GuzzleHttp\Client();
13093

131-
$pusher->set_logger( new MyLogger() );
94+
$pusher = new Pusher\Pusher(
95+
$app_key,
96+
$app_secret,
97+
$app_id,
98+
array(),
99+
$custom_client
100+
)
101+
);
132102
```
133103

134-
If you use the above example in code executed from the console/terminal the
135-
debug information will be output there. If you use this within a web app then
136-
the output will appear within the generated app output e.g. HTML.
104+
This allows you to pass in your own middleware, see the tests for an
105+
[example](tests/acceptance/middlewareTest.php).
137106

138107
## Publishing/Triggering events
139108

@@ -217,10 +186,10 @@ $result = $pusher->triggerBatch($batch);
217186
foreach ($result->batch as $i => $attributes) {
218187
echo "channel: {$batch[$i]['channel']}, name: {$batch[$i]['name']}";
219188
if (isset($attributes->subscription_count)) {
220-
echo ", subscription_count: {$attributes->subscription_count}";
189+
echo ", subscription_count: {$attributes->subscription_count}";
221190
}
222191
if (isset($attributes->user_count)) {
223-
echo ", user_count: {$attributes->user_count}";
192+
echo ", user_count: {$attributes->user_count}";
224193
}
225194
echo PHP_EOL;
226195
}
@@ -294,13 +263,13 @@ these steps:
294263

295264
```php
296265
$pusher = new Pusher\Pusher(
297-
$app_key,
298-
$app_secret,
299-
$app_id,
300-
array(
301-
'cluster' => $app_cluster,
302-
'encryption_master_key_base64' => "<your base64 encoded master key>"
303-
)
266+
$app_key,
267+
$app_secret,
268+
$app_id,
269+
array(
270+
'cluster' => $app_cluster,
271+
'encryption_master_key_base64' => "<your base64 encoded master key>"
272+
)
304273
);
305274
```
306275

@@ -445,8 +414,8 @@ approach consumes (number of channels + 1) messages!
445414
$subscription_counts = array();
446415
foreach ($pusher->get_channels()->channels as $channel => $v) {
447416
$subscription_counts[$channel] =
448-
$pusher->get_channel_info(
449-
$channel, array('info' => 'subscription_count'))->subscription_count;
417+
$pusher->get_channel_info(
418+
$channel, array('info' => 'subscription_count'))->subscription_count;
450419
}
451420
var_dump($subscription_counts);
452421
```
@@ -468,16 +437,16 @@ The `$response` is in the format:
468437

469438
```php
470439
Array (
471-
[body] => {"users":[{"id":"a_user_id"}]}
472-
[status] => 200
473-
[result] => Array (
474-
[users] => Array (
475-
[0] => Array (
476-
[id] => a_user_id
477-
),
478-
/* Additional users */
479-
)
480-
)
440+
[body] => {"users":[{"id":"a_user_id"}]}
441+
[status] => 200
442+
[result] => Array (
443+
[users] => Array (
444+
[0] => Array (
445+
[id] => a_user_id
446+
),
447+
/* Additional users */
448+
)
449+
)
481450
)
482451
```
483452

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
"keywords": ["php-pusher-server", "pusher", "rest", "realtime", "real-time", "real time", "messaging", "push", "trigger", "publish", "events"],
55
"license": "MIT",
66
"require": {
7-
"php": "^7.1|^8.0",
7+
"php": "^7.2.5|^8.0",
88
"ext-curl": "*",
9+
"guzzlehttp/guzzle": "^7.2",
910
"psr/log": "^1.0",
1011
"paragonie/sodium_compat": "^1.6"
1112
},

0 commit comments

Comments
 (0)