A
A
Alisher Aidarkhan2019-03-27 12:22:22
PHP
Alisher Aidarkhan, 2019-03-27 12:22:22

How to run a Workerman Websocket server next to Apache?

There is an Apache server. It is running on port 80.
Project architecture
- workspace
-- api
-- js
-- img
-- css
-- views
--socket
-- app.js
-- index.js The socket
folder contains the sever.php file, which contains this the code:

<?php
    use Workerman\Worker;
    use PHPSocketIO\SocketIO;

    require_once __DIR__ . '/vendor/autoload.php';
    
    // listen port 2021 for socket.io client
    $io = new SocketIO(3001);
    $io->on('connection', function($socket)use($io){
        $io->emit('listen', $msg);
    });
    
    Worker::runAll();
?>

This miracle is launched through the console command: php server.php start
Runs well and without errors in the code.
Apache: running on port 80
Workerman: running on port 3001
To subscribe to sockets I use Socket.io on the AngularJS front.
Connection file:
angular
  .module('kanban')
    .factory('Socket', function (socketFactory) {
        return socketFactory({
            ioSocket: io.connect('http://[IP]:3001')
        });
    });

But there is an error in the console: http://[IP]:3001/socket.io/?EIO=3&transport=pollin... net::ERR_CONNECTION_TIMED_OUT
1) How to solve this problem?
2) Is it necessary to write something in the Apache configurations
3) Does everything start correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vldud, 2019-03-30
@vldud

1) Look towards the client, google for "socket.io ERR_CONNECTION_TIMED_OUT"
2) What does Apache have to do with it? He does not participate in this scheme.
3) It seems to start correctly.
And by the way, the listen event is emitted on the server, you do not seem to process it on the client in any way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question