autobahn.min.js:181 WebSocket connection to 'wss://site.com/socket/' failed: (anonymous)

41 views Asked by At

I have a website on Wordpress, on the main page the news is updated via sockets. Sometimes the following error appears: autobahn.min.js:181 WebSocket connection to 'wss://site.com/socket/' failed: (anonymous) @ autobahn.min.js:181 [email protected]:182 r._create_transport @ autobahn.min.js:81 [email protected]:84

I use this version of the script https://cdnjs.cloudflare.com/ajax/libs/autobahn/20.9.2/autobahn.min.js

The site runs via Cloudflare

Socket code ``` add_action('save_post_news', 'update_front_news', 100, 2); function update_front_news($post_id) {

   if (wp_is_post_revision($post_id) || get_post($post_id)->post_status != 'publish') return;

   $terms = wp_get_post_terms($post_id, 'news-list', ['fields' => 'slugs']);

   $users = carbon_get_post_meta(16, 'authors_column_sticked_authors');

   $post_author = NULL;
   $authorID = get_post_field('post_author');
   foreach ($users as $user) {

    if ($authorID == $user['id']) {
        $post_author = $authorID;
    }
}

$context = new ZMQC();
$socket = $context->getSocket(ZMQ::SOCKET_PUSH);
$socket->connect("tcp://127.0.0.1:5555");
$socket->send(json_encode([
    'event' => 'news_block_update',
    'post_id' => $post_id,
    'update_blocks' => $terms,
    'district_update_blocks' => wp_get_post_terms($post_id, 'news-district', ['fields' =>              'slugs']),
    'event_type' => get_post_type($post_id),
    'author_id' => $post_author,
]));

} ```

The hosting has two places configured where the port for the listener is specified, in one section 5555 and in the other 8888.

<?php
require_once(__DIR__ . '/wp-load.php');
require __DIR__ . '/vendor/autoload.php';

require_once('./wp-content/themes/sitetheme/components/topic-bar.php');
require_once('./wp-content/themes/sitetheme/components/news-templates/culture-news-template.php');
require_once('./wp-content/themes/sitetheme/components/news-templates/district-news-template.php');
require_once('./wp-content/themes/sitetheme/components/news-templates/economy-tempalte.php');
require_once('./wp-content/themes/sitetheme/components/news-templates/incidents-news-template.php');
require_once('./wp-content/themes/sitetheme/components/news-templates/main-news-template.php');
require_once('./wp-content/themes/sitetheme/components/news-templates/most-read-news-template.php');
require_once('./wp-content/themes/sitetheme/components/news-templates/newspapers-template.php');
require_once('./wp-content/themes/sitetheme/components/news-templates/pallete-news-template.php');
require_once('./wp-content/themes/sitetheme/components/news-templates/society-news-tempalte.php');
require_once('./wp-content/themes/sitetheme/components/news-templates/sport-news-template.php');
require_once('./wp-content/themes/sitetheme/components/news-templates/urban-economy-news-template.php');
require_once('./wp-content/themes/sitetheme/components/news-templates/world-news-template.php');
require_once('./wp-content/themes/sitetheme/components/news-templates/author-columns-template.php');
require_once('./wp-content/themes/sitetheme/components/news-templates/top-three-news-template.php');
require_once('./wp-content/themes/sitetheme/components/news-templates/timeline-news-template.php');
require_once('./wp-content/themes/sitetheme/components/news-templates/video-news-tempalte.php');
//require_once('./wp-content/themes/sitetheme/components/news-templates/district-tablet-news-template.php');

use Thruway\Peer\Client;
use Thruway\Peer\Router;
use Thruway\Transport\RatchetTransportProvider;

$loop = React\EventLoop\Factory::create();

$pusher = new Client("realm1", $loop);

$pusher->on('open', function ($session) use ($loop) {
    $context = new React\ZMQ\Context($loop);

    $pull = $context->getSocket(ZMQ::SOCKET_PULL);
    $pull->bind('tcp://0.0.0.0:5555');

    $pull->on('message', function ($entry) use ($session) {
        $entryData = json_decode($entry, true);

        $category_render_templates = [
            'novosti-mira' => 'render_most_read_news_template',
            'obshhestvo' => 'render_society_news_template',
            'ekonomika' => 'render_urban_economy_news_template',
            'ekonomika-2' => 'render_economy_news_template',
            'kultura' => 'render_culture_news_template',
            'sport' => 'render_sport_news_template',
            'palitra-dnya' => 'render_pallete_news_template',
        ];

        $new_categories_post = array();

        $cats = array_keys($category_render_templates);

        var_dump($entryData['event']);

        if ($entryData['event'] === 'news_block_update') {
            foreach ($entryData['update_blocks'] as $cat) {
                if (!in_array($cat, $cats)) continue;

                $block_html = ob_start();
                $category_render_templates[$cat]();
                $block_html = ob_get_clean();
                ob_end_flush();

                array_push($new_categories_post, [
                    'data' => $block_html,
                    'cat' => $cat
                ]);
            }
            $session->publish('news', [json_encode($new_categories_post)]);
        }
    });
});

$router = new Router($loop);
$router->addInternalClient($pusher);
$router->addTransportProvider(new RatchetTransportProvider("0.0.0.0", 8888));
$router->start();

0

There are 0 answers