@@ -18,22 +18,16 @@ Or add to `composer.json`:
18
18
19
19
``` json
20
20
"require" : {
21
- "pusher/pusher-php-server" : " ^5 .0"
21
+ "pusher/pusher-php-server" : " ^6 .0"
22
22
}
23
23
```
24
24
25
25
and then run ` composer update ` .
26
26
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
-
33
27
## Supported platforms
34
28
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 ) .
37
31
* Other PHP frameworks - supported provided you are using a supported version of PHP.
38
32
39
33
## Pusher Channels constructor
@@ -60,46 +54,23 @@ The fourth parameter is an `$options` array. The additional options are:
60
54
* ` timeout ` - the HTTP timeout
61
55
* ` useTLS ` - quick option to use scheme of https and port 443.
62
56
* ` cluster ` - specify the cluster where the application is running from.
63
- * ` curl_options ` - array with custom curl commands
64
57
* ` encryption_master_key ` - a 32 char long key. This key, along with the
65
58
channel name, are used to derive per-channel encryption keys. Per-channel
66
59
keys are used encrypt event data on encrypted channels.
67
60
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 :
70
63
71
64
``` 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 );
88
70
```
89
71
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
-
97
72
## Logging configuration
98
73
99
- It is strongly recommended that you configure a logger.
100
-
101
- ### PSR-3 Support
102
-
103
74
The recommended approach of logging is to use a
104
75
[ PSR-3] ( https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md )
105
76
compliant logger implementing ` Psr\Log\LoggerInterface ` . The ` Pusher ` object
@@ -112,28 +83,26 @@ implements `Psr\Log\LoggerAwareInterface`, meaning you call
112
83
$pusher->setLogger($logger);
113
84
```
114
85
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
120
87
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 :
123
90
124
91
``` php
125
- class MyLogger {
126
- public function log( $msg ) {
127
- print_r( $msg . "\n" );
128
- }
129
- }
92
+ $custom_client = new GuzzleHttp\Client();
130
93
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
+ );
132
102
```
133
103
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 ) .
137
106
138
107
## Publishing/Triggering events
139
108
@@ -217,10 +186,10 @@ $result = $pusher->triggerBatch($batch);
217
186
foreach ($result->batch as $i => $attributes) {
218
187
echo "channel: {$batch[$i]['channel']}, name: {$batch[$i]['name']}";
219
188
if (isset($attributes->subscription_count)) {
220
- echo ", subscription_count: {$attributes->subscription_count}";
189
+ echo ", subscription_count: {$attributes->subscription_count}";
221
190
}
222
191
if (isset($attributes->user_count)) {
223
- echo ", user_count: {$attributes->user_count}";
192
+ echo ", user_count: {$attributes->user_count}";
224
193
}
225
194
echo PHP_EOL;
226
195
}
@@ -294,13 +263,13 @@ these steps:
294
263
295
264
``` php
296
265
$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
+ )
304
273
);
305
274
```
306
275
@@ -445,8 +414,8 @@ approach consumes (number of channels + 1) messages!
445
414
$subscription_counts = array();
446
415
foreach ($pusher->get_channels()->channels as $channel => $v) {
447
416
$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;
450
419
}
451
420
var_dump($subscription_counts);
452
421
```
@@ -468,16 +437,16 @@ The `$response` is in the format:
468
437
469
438
``` php
470
439
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
+ )
481
450
)
482
451
```
483
452
0 commit comments