@@ -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
2525and 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-
10374The 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 )
10576compliant 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);
217186foreach ($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();
446415foreach ($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}
451420var_dump($subscription_counts);
452421```
@@ -468,16 +437,16 @@ The `$response` is in the format:
468437
469438``` php
470439Array (
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
0 commit comments