laravel-websockets icon indicating copy to clipboard operation
laravel-websockets copied to clipboard

Statistics not storing to the database

Open kehood opened this issue 4 years ago • 7 comments

Websockets working perfectly on local and production. Neither one is writing entries to the websockets_statitistics_entry table. I've tried changing perform_dns_lookup to true as well to no avail. Any suggestions?

kehood avatar Sep 08 '21 20:09 kehood

+1. It seems that they broke something. it seems that this line:

71.  $statistic->isEnabled()

will always return true. Source file: vendor\beyondcode\laravel-websockets\src\Statistics\Logger\HttpStatisticsLogger.php

Have you solved your issue?

Temepest74 avatar Sep 14 '21 13:09 Temepest74

I am having this issue as well.

nissmotion avatar Sep 14 '21 13:09 nissmotion

I have not solved this issue yet, was hoping someone with more experience with the package had a solution.

kehood avatar Sep 14 '21 13:09 kehood

I have not solved this issue yet, was hoping someone with more experience with the package had a solution.

I could try to solve it. But rn I have a very strict deadline for the project. It would be amazing if the devs would help with it.

Temepest74 avatar Sep 14 '21 16:09 Temepest74

I am having the same issue working on local machine and I solved it by changing APP_URL in .env APP_URL=http://127.0.0.1:8000

Mr-Billy-Boy avatar Nov 25 '21 06:11 Mr-Billy-Boy

I have the same problem. Strange that there are no errors around this in the laravel log.

gcleaves avatar Jun 14 '22 09:06 gcleaves

I have the same problem. Strange that there are no errors around this in the laravel log.

I forgot to post my solution. The latest 1.x versions are broken on the statistics side of things. Go and use the beta 2.x versions and it will work like a charm. I am using it in prod for like 3 months and I saw no issues

Temepest74 avatar Jun 14 '22 09:06 Temepest74

I had the same problem here, but with Laravel 10, it iss not possible to use the beta versions. I can see that there is a fundamental redesign of Laravel-websockets 2.x concerning the Statistics but on 1.14 version this code does not work as attempted :

HttpStatisticsLogger.php -> Line 79

$this
    ->browser
    ->post(
        action([WebSocketStatisticsEntriesController::class, 'store']),    
        ['Content-Type' => 'application/json'],
        Utils::streamFor(json_encode($postData))
);

everything seems correct except the $this->browser who probably should be misconfigured. I actually succeeded to send a post request from Insomnia with the information in the $this->browser->post() method so the problem should probably be the poster.

And actually I found out it was not correctly configured as we can see here in StartWebSocketServer :

$connector = new Connector($this->loop, [
    'dns' => $this->getDnsResolver(),
    'tls' => [
        'verify_peer' => config('app.env') === 'production',
        'verify_peer_name' => config('app.env') === 'production',
    ],
]);

$browser = new Browser($this->loop, $connector);

If I replace $this->getDnsResolver() with 127.0.0.1 it works. So the problem comes from the Connecter receiving the 'dns' :

vendor/react/socket/src/Connector.php Line 93 :

        if ($context['dns'] !== false) 
        {
            if ($context['dns'] instanceof ResolverInterface) 
            {
                $resolver = $context['dns'];
            } 
            else 
            {
                if ($context['dns'] !== true) {
                    $config = $context['dns'];
                } else {
                    // try to load nameservers from system config or default to Google's public DNS
                    $config = DnsConfig::loadSystemConfigBlocking();
                    if (!$config->nameservers) {
                        $config->nameservers[] = '8.8.8.8'; // @codeCoverageIgnore
                    }
                }

                $factory = new DnsFactory();
                $resolver = $factory->createCached(
                    $config,
                    $loop
                );
            }

            if( $context['happy_eyeballs'] === true ) 
            {
                $tcp = new HappyEyeBallsConnector($loop, $tcp, $resolver);
            } 
            else 
            {
                $tcp = new DnsConnector($tcp, $resolver);
            }
        }

When focusing on the code, I figure out that the `happy_eyeballs [ always true when not indicated ] creates à new HappyEyeBallsConnctor instead of the DnsConnector normally working. So :

I tried to add a happy_eyeballs => false in the connector context array and it solved the problem.

$connector = new Connector($this->loop, [
    'dns' => $this->getDnsResolver(),
    'tls' => [
        'verify_peer' => config('app.env') === 'production',
        'verify_peer_name' => config('app.env') === 'production',
     ],
    'happy_eyeballs' => false
]);

Hope this helps.

mho22 avatar Apr 14 '23 15:04 mho22