Git Product home page Git Product logo

Comments (12)

morozovsk avatar morozovsk commented on July 19, 2024
  1. как считаете коннекты?
  2. 'master' - используется для соединения с другим процессом посредством сокета в текстовом формате, в Chat2 можно посмотреть пример реализации.

from websocket.

borodatych avatar borodatych commented on July 19, 2024

Считается, дак просто, count($this->userIds).

from websocket.

morozovsk avatar morozovsk commented on July 19, 2024

у меня не было такого кода в примере.
покажите ваш модифицированный код

from websocket.

borodatych avatar borodatych commented on July 19, 2024

Handle:

protected function onServiceMessage($connectionId, $data)
    {
        $data = json_decode($data);
        $message = @$data->message;
        $action = @$data->action;
        $toUser = @$data->userId;

        if( $action )
        {
            if( 'readNewMsg'==$action )
            {
                $send = "no";
                $message = $action;
                foreach( $this->userIds as $clientId => $userId )
                {
                    if( $toUser == $userId )
                    {
                        $send = "ok";
                        $this->sendToClient($clientId,$message);
                    }
                }
                $this->sendToService($connectionId,json_encode(array('send' => $send)));
            }
            if( 'pingUser'==$action )
            {
                $online = FALSE;
                foreach( $this->userIds as $clientId => $userId )
                {
                    if( $toUser == $userId ) $online = TRUE;
                }
                $this->sendToService($connectionId,json_encode(array('online' => $online)));
            }
            if( 'countUsers'==$action )
            {
                $msg = NULL;
                if( 'full'==$toUser ) $msg = json_encode(array('count' => count($this->userIds),'users' => $this->userIds));
                elseif( 'count'==$toUser ) $msg = count($this->userIds);
                elseif( 'list'==$toUser ) $msg = json_encode($this->userIds);
                $this->sendToService($connectionId,$msg);
            }
        }
        else foreach( $this->userIds as $clientId => $userId ) if( $toUser == $userId ) $this->sendToClient($clientId,$message);
    }

В момент же открытия:

protected function onOpen($connectionId, $info) /// Вызывается при соединении с новым клиентом
    {
        ///$message = 'пользователь #' . $connectionId . ' : ' . var_export($info, true) . ' ' . stream_socket_get_name($this->clients[$connectionId], true);
        ///foreach( $this->clients as $clientId => $client ) $this->sendToClient($clientId, $message);

        $info['GET']; /// or use $info['Cookie'] for use PHPSESSID or $info['X-Real-IP'] if you use proxy-server like nginx
        parse_str(substr($info['GET'], 1), $_GET);//parse get-query
        ///var_export($_GET['id']);
        $userId = @$_GET['userId'];
        $this->userIds[$connectionId] = $userId;
    }

Дак вот, просто считаю $this->userIds или неправильно?

from websocket.

morozovsk avatar morozovsk commented on July 19, 2024

Да вроде правильно, а этот код я надеюсь не удалялся?

protected function onClose($connectionId) {//it is called when existed connection is closed
unset($this->userIds[$connectionId]);
}

from websocket.

borodatych avatar borodatych commented on July 19, 2024

На месте)).
Ну значит живые получается.
На текущий момент уже 6188 !!

from websocket.

morozovsk avatar morozovsk commented on July 19, 2024

а какая дневная посещаемость сайта (сколько уникальных пользователей в день), что столько соединений?

from websocket.

olegius88 avatar olegius88 commented on July 19, 2024

Здравствуйте. Постоянно наблюдаю активные соединения, если было прерывание интернета или если браузер грохнуть в диспетчере задач. Проблему решил посыланием пинга и ожиданием понга по таймеру. если ответ не пришел, убиваю соединение

from websocket.

borodatych avatar borodatych commented on July 19, 2024

@olegius88
Если не затруднит, поделитесь скриптиком.
Спасибо

from websocket.

borodatych avatar borodatych commented on July 19, 2024

@olegius88
Что вы подразумеваете под словом посылает пинг?
Есть какой то метод?
Или просто маленькое сообщение вы так обозначили?

from websocket.

borodatych avatar borodatych commented on July 19, 2024

@morozovsk
Может вы прокомментируете?

from websocket.

borodatych avatar borodatych commented on July 19, 2024

Спасибо! Все рабоатет!

from websocket.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.