pusher / pusher-http-php

PHP library for interacting with the Pusher Channels HTTP API
https://pusher.com/docs/server_api_guide
1.41k stars 307 forks source link

Connection refused on shared host #300

Closed MohamedSR closed 3 years ago

MohamedSR commented 3 years ago

Actually it's not a bug, i received Connection refused on shared host though it work fine on localhost

----- My configuration -------------

` 'pusher' => [
            'driver' => 'pusher',
            'key' => env('PUSHER_APP_KEY'),
            'secret' => env('PUSHER_APP_SECRET'),
            'app_id' => env('PUSHER_APP_ID'),
            'options' => [
                'cluster' => 'eu',
                'useTLS' => true
            ],
        ],`

----- My event solution 1 -------

`<?php
namespace App\Events;
use Pusher\Pusher;
use GuzzleHttp\Client;

class PusherEvent extends Event
{
   /**
   * Create a new event instance.
   *
   * @return void
   */
   public function __construct($event, $message)
   {
      $custom_client = new Client();
      $pusher = new Pusher(
         env('PUSHER_APP_KEY'),
         env('PUSHER_APP_SECRET'),
         env('PUSHER_APP_ID'),
         [
            'cluster' => env('PUSHER_APP_CLUSTER'),
            'useTLS' => true
         ],
         $custom_client
      );
      $pusher->trigger( 'channel_name', $event, $message );
   }
}`

---- my event solution 2 -------------

<?php

namespace App\Events;

use Illuminate\Queue\SerializesModels;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Broadcasting\Channel;

class NewOrder implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public $message;
    public function __construct($message)
    {
        $this->message = $message;
    }
    public function broadcastOn()
    {
        return ['chanel_name'];
    }
    public function broadcastWith()
    {
        return ['message' => $this->message];
    }
    public function broadcastAs() {

        return 'new-order';

    }
}

----- How i trigger the event ---------- event(new PusherEvent("new-order",$message));

------ Response received -----------

Connection refused for URI http://api-eu.pusher.com/apps/xxxxxx/events?auth_key=xxxxxxxxx&auth_timestamp=1616497319&auth_version=1.0&body_md5=xxxxxxxxxxxxxxxxx&auth_signature=xxxxxxxxxxxxxxxxxxxxxxxxx

benw-pusher commented 3 years ago

Do you receive any more information in the stack trace about why the connection is refused (for e.g a certificate error)? Do you get the same error when TLS is set to false - 'useTLS' => false?

elverkilde commented 3 years ago

It sounds like something is blocking traffic between your shared host and Pusher. Can you issue a ping to api-eu.pusher.com?

If you are not getting responses on the pings, you could try the same thing with traceroute, e.g. traceroute api-eu.pusher.com (depending on your OS etc). That would tell you what's blocking the traffic.

MohamedSR commented 3 years ago

Do you receive any more information in the stack trace about why the connection is refused (for e.g a certificate error)? Do you get the same error when TLS is set to false - 'useTLS' => false?

in StreamHandler.php line 72

at StreamHandler->__invoke(object(Request), array('http_errors' => false, 'base_uri' => 'https://api-eu.pusher.com:443', 'synchronous' => true, 'handler' => object(HandlerStack), 'allow_redirects' => array('max' => 5, 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, 'track_redirects' => false), 'decode_content' => true, 'verify' => true, 'cookies' => false, 'idn_conversion' => false)) in PrepareBodyMiddleware.php line 64

at PrepareBodyMiddleware->__invoke(object(Request), array('http_errors' => false, 'base_uri' => 'https://api-eu.pusher.com:443', 'synchronous' => true, 'handler' => object(HandlerStack), 'allow_redirects' => array('max' => 5, 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, 'track_redirects' => false), 'decode_content' => true, 'verify' => true, 'cookies' => false, 'idn_conversion' => false)) in Middleware.php line 31

at Middleware::GuzzleHttp{closure}(object(Request), array('http_errors' => false, 'base_uri' => 'https://api-eu.pusher.com:443', 'synchronous' => true, 'handler' => object(HandlerStack), 'allow_redirects' => array('max' => 5, 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, 'track_redirects' => false), 'decode_content' => true, 'verify' => true, 'cookies' => false, 'idn_conversion' => false)) in RedirectMiddleware.php line 71

at RedirectMiddleware->__invoke(object(Request), array('http_errors' => false, 'base_uri' => 'https://api-eu.pusher.com:443', 'synchronous' => true, 'handler' => object(HandlerStack), 'allow_redirects' => array('max' => 5, 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, 'track_redirects' => false), 'decode_content' => true, 'verify' => true, 'cookies' => false, 'idn_conversion' => false)) in Middleware.php line 61

at Middleware::GuzzleHttp{closure}(object(Request), array('http_errors' => false, 'base_uri' => 'https://api-eu.pusher.com:443', 'synchronous' => true, 'handler' => object(HandlerStack), 'allow_redirects' => array('max' => 5, 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, 'track_redirects' => false), 'decode_content' => true, 'verify' => true, 'cookies' => false, 'idn_conversion' => false)) in HandlerStack.php line 75

at HandlerStack->__invoke(object(Request), array('http_errors' => false, 'base_uri' => 'https://api-eu.pusher.com:443', 'synchronous' => true, 'handler' => object(HandlerStack), 'allow_redirects' => array('max' => 5, 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, 'track_redirects' => false), 'decode_content' => true, 'verify' => true, 'cookies' => false, 'idn_conversion' => false)) in Client.php line 331

at Client->transfer(object(Request), array('http_errors' => false, 'base_uri' => 'https://api-eu.pusher.com:443', 'synchronous' => true, 'handler' => object(HandlerStack), 'allow_redirects' => array('max' => 5, 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, 'track_redirects' => false), 'decode_content' => true, 'verify' => true, 'cookies' => false, 'idn_conversion' => false)) in Client.php line 168

at Client->requestAsync('POST', object(Uri), array('query' => array('auth_key' => 'xxxxxxx', 'auth_timestamp' => 1616525290, 'auth_version' => '1.0', 'body_md5' => 'xxxxxxxx', 'auth_signature' => 'xxxxxxxxxx'), 'http_errors' => false, 'base_uri' => 'https://api-eu.pusher.com:443', 'synchronous' => true, 'handler' => object(HandlerStack), 'allow_redirects' => array('max' => 5, 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, 'track_redirects' => false), 'decode_content' => true, 'verify' => true, 'cookies' => false, 'idn_conversion' => false, '_conditional' => array('User-Agent' => 'GuzzleHttp/7')))

in Client.php line 187

at Client->request('POST', '/apps/xxxxxxxxx/events', array('query' => array('auth_key' => 'xxxxxx', 'auth_timestamp' => 1616525290, 'auth_version' => '1.0', 'body_md5' => 'xxxxxx', 'auth_signature' => 'xxxxxxxxxx'), 'headers' => array('Content-Type' => 'application/json', 'X-Pusher-Library' => 'pusher-http-php 6.0.1'), 'body' => '{"name":"new-order","data":"\"vous avez une nouvelle commande ref: xxxxxxxx-70\"","channels":["livresto"]}', 'http_errors' => false, 'base_uri' => 'https://api-eu.pusher.com:443', 'synchronous' => true)) in ClientTrait.php line 95

at Client->post('/apps/xxxxxx/events', array('query' => array('auth_key' => 'xxxxxxxxxxxxxxx', 'auth_timestamp' => 1616525290, 'auth_version' => '1.0', 'body_md5' => 'xxxxxxxxxxxx', 'auth_signature' => 'xxxxxxxx'), 'headers' => array('Content-Type' => 'application/json', 'X-Pusher-Library' => 'pusher-http-php 6.0.1'), 'body' => '{"name":"new-order","data":"\"vous avez une nouvelle commande ref: 1616525290-70\"","channels":["livresto"]}', 'http_errors' => false, 'base_uri' => 'https://api-eu.pusher.com:443'))in Pusher.php line 408 at Pusher->trigger(array('livresto'), 'new-order', 'vous avez une nouvelle commande ref: 1616525290-70')in PusherEvent.php line 26

MohamedSR commented 3 years ago

It sounds like something is blocking traffic between your shared host and Pusher. Can you issue a ping to api-eu.pusher.com?

If you are not getting responses on the pings, you could try the same thing with traceroute, e.g. traceroute api-eu.pusher.com (depending on your OS etc). That would tell you what's blocking the traffic.

Unfortunately my shared host doent provide ssh

elverkilde commented 3 years ago

In that case I am not sure how to proceed. This doesn't sound like a problem with the Pusher SDK, but rather your environment. I would suggest you somehow verify whether this server allows outgoing traffic on port 443 or 80.

If someone is managing this server for you, you might be able to ask them to investigate?

MohamedSR commented 3 years ago

In that case I am not sure how to proceed. This doesn't sound like a problem with the Pusher SDK, but rather your environment. I would suggest you somehow verify whether this server allows outgoing traffic on port 443 or 80.

If someone is managing this server for you, you might be able to ask them to investigate?

Yes it's not related to the SDK though it works well on localhost, i asked them to investigate and i am waiting for the response

MohamedSR commented 3 years ago

It works well when i change the cluser from eu to mt1, Thanks @elverkilde and @ben-pusher :)