V
V
Vitaly Vitaly2015-12-12 13:06:22
JavaScript
Vitaly Vitaly, 2015-12-12 13:06:22

Which realtime method to choose?

Hello! The task is to implement the realtime main page, all users who are on the main page simultaneously receive a real-time page update, as an example (an object feed that is updated when someone has added a new object), as well as a change in statistics and a counter .
I think about node.js + socket.io, but of course I would like an implementation in php.
What about comet, ajax, phpdeamon? With 500 simultaneous connections.
I also thought that phpdeamon would process the data - update the json file, and users would access the file and receive information.
Pusher service - I decided not to use it, I would still like not to use third-party services.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Osher, 2015-12-12
@V_Tjuryakin

Laravel is great at broadcasting through redis.
A post is created - shoot an event. Give json.
On the client, you receive data, create a block.
laravel.com/docs/5.1/events#broadcasting-events
// EDIT
See an example implementation via redis.
Also, queue must be configured, also via redis.
Everything is described in the documentation. And this is what the code looks like.

// .env
BROADCAST_DRIVER=redis

// app/http/controllers/PostController.php

class PostController extends Controller
{
    public function store(Request $request)
    {
        $post = Post::create($request);
        
        Event::fire(new PostCreated($post));
        
        return $post;
    }
}

// app/events/PostCreated.php

class PostCreated extends Event implements ShouldBroadcast
{
    use SerializesModels;
    
    private $post;
    
    public function __construct(Post $post)
    {
        $this->post = $post;
    }
    
    public function broadcastOn()
    {
        return [
            'post_created',
        ];
    }
    
    public function broadcastAs()
    {
        return 'post_created';
    }
    
    public function broadcastWith()
    {
        return $this->post;
    }
}

F
FZambia, 2016-06-03
@FZambia

If you have looked towards pusher.com, but do not want to use a third-party service, look towards Centrifugo

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question