Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rohitkhatri's avatar

@mstnorris What is the use of redis in it? and I followed along with your tutorial, therefore It's working, but I wanted to know how to start it as background task, because when I type the commands in terminal, task stops as soon as I close the terminal, and another thing, Is there any facility in socket.io to subscribe to any channel and when data is broadcast to a particular channel(dynamically), clients which are subscribed to the channel will receive the data?

zabi.zamir's avatar

I used this code and everything works fine on localhost, but it does not work from external ip. This is the error I get:

GET http://serverip:3000/socket.io/?EIO=3&transport=polling&t=LDrVJCA Request.create @ socket.io.min.js:1Request @ socket.io.min.js:1XHR.request @ socket.io.min.js:1XHR.doPoll @ socket.io.min.js:1Polling.poll @ socket.io.min.js:1Polling.doOpen @ socket.io.min.js:1Transport.open @ socket.io.min.js:1Socket.open @ socket.io.min.js:1Socket @ socket.io.min.js:1Socket @ socket.io.min.js:1Manager.open.Manager.connect @ socket.io.min.js:2(anonymous function) @ socket.io.min.js:3 feedTest:1 XMLHttpRequest cannot load http://serverip:3000/socket.io/?EIO=3&transport=polling&t=LDrVJCA. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://example.com' is therefore not allowed access. The response had HTTP status code 502.

Please help me anyone as I already search everywhere online I could not find working solution. Any help would be highly appreciated. Thanks

Hamelraj's avatar

@mstnorris till i run node socket.js i will get output like you You should see "Listening on Port 3000" but in root i have tried this redis-server --port 3001 but in my CMD im getting i think im rong ??

'redis-server' is not recognized as an internal or external command,
operable program or batch file.
1 like
Doculon's avatar

Kind of a newbie question, but what is the role of redis in here? i tried running only the socket.io server and it still work.

davorminchorov's avatar

Redis is the guy who transfers data from one server to another. In other words, it publishes a message on the Laravel side, and the Node Redis client listens (subscribes) on channels for new messages and receives them as they come in.

1 like
broctagon's avatar

Excellent tutorial !!

As i have implemented it and it is running perfectly. Only thing i want to know how to fire the event automatically in background every 5 minutes.Please help me out.

davorminchorov's avatar

use setInterval() on the nodejs server and send the notification/message every 5 minutes?

1 like
broctagon's avatar

@Ruffles Thanks for valuable reply , How to send notification/message every 5 minutes. as i do not need my terminal open for redis server and node. mainly i want to handle these things automatically without cron. Can anyone help me on this plz ?

vahabv's avatar

is it possible that use socket io without using homestead?

Hackmastr's avatar

@vahabv, yes, just install Laravel(using Composer), than download and install redis, install nodejs, express...(using the what OP said...), that's all :)

jonnywilliamson's avatar

Well basically all of this is now completely superseded by the official Laravel-Echo-Server library which now works with Laravel Notifications (5.3)

It's important to read the documents very carefully. This now supports authenticated channels (ie private channels etc) something which this thread's method did not supply.

https://laravel.com/docs/5.3/broadcasting#receiving-broadcasts

The JS library and more details can be found here: https://github.com/tlaverdure/laravel-echo-server

That's not to say you can't use the method as outlined in this thread, it's just that a much more official and robust solution has been created and if it suits, should probably be used over this.

Enjoy.

1 like
kingman's avatar

I'm getting an error .

Class 'Illuminate\Support\Facades\App\Events\EventName' not found

info.amit.dahiya@gmail.com's avatar

For Laravel 5.4 I have configured it For Notification broadcasting, follow below-given steps and it is working fine:

  1. npm install express ioredis socket.io –save

Your package.json file will look like { "private": true, "devDependencies": { "gulp": "^3.8.8", "laravel-elixir": "*" }, "dependencies": { "express": "^4.12.4", "ioredis": "^1.4.0", "redis": "^0.12.1", "socket.io": "^1.3.5" } }

  1. composer require predis/predis

The require part of your composer.json file will look like "require": { "laravel/framework": "5.4.*", "predis/predis": "^1.1@dev" },

  1. php artisan make:event EventName

Open up your newly create EventName.php event class found within the app/Events directory. Make sure that it implements ShouldBroadcast Event file look like:

shahshawaiz's avatar

Great tutorial. I had a tiny issue though. redis at socket.js was not receiving any broadcasted message from laravel's events. Sorted this issue out by setting QUEUE_DRIVER to "sync".

murlidharfichadia@gmail.com's avatar

@mstnorris Hi, I dont understand this line: in 12th step of your tutorial.

You are telling to look for socket.io.js file in js folder but there is no mention of socket.io.js file anywhere. Currently, I dont have socket.io.js file in js folder and so I get an error: GET http://test.app/js/socket.io.js 404 (Not Found) test:14 Uncaught ReferenceError: io is not defined at test:14

zahoor's avatar

Its not working for me. What will be the mistake i have done. I am getting the console log value but its not at all changing the value in display page ?

zahoor's avatar

Thanks,I rectified the issue thank you for wonderful guide

1 like
usamamashkoor's avatar

Hi Thanks for this wonderful guide can you please tell me how can i @mstnorris on windows i can run the node socket.js on cmd but how can i run the node socket.js file on the server for all the time i am on Ubuntu 16.04 server. Thanks in advance.

sirexzib's avatar

Hi, how do u deploy this for a live server? My server is currently live and it just wont work, following exactly what you said.

sirexzib's avatar

I keep getting this:

ERR_CONNECTION_TIMED_OUT

FrubeBottle494's avatar

Hey, I have just followed your tutorial and can't seem to get it working. The redis server is listening and my socket.js file starts, however I am getting "http://127.0.0.1:8000/socket.io/socket.io.js net::ERR_ABORTED". I have tried using it in homestead too and my error still persists.

I assume /socket.io/socket.io.js is created by the server. I am also running socket 6.+ now. But never the less I my server never creates /socket/socket.io.js

Any ideas? Really need some help!

FrubeBottle494's avatar

I also just want to add that we can get /socket.io/socket.io.js when specifying the port in the browser.

E.g If I manually go to mysite.blah:3000/socket.io/socket.io.js, but when just on mysite.blah it doesn't work and can't find it.

even tried changing all the ports to 8080

1 like

Please or to participate in this conversation.