dpw30157 2016-02-18 09:48
浏览 19

是否有任何Symfony听众做套接字工作?

How can I create a listener in Symfony to do such as the sockets do in the following example:

public function socketestAction($sizeData)    //For TEST
    {
        session_write_close();
        ob_implicit_flush(true);
        ob_end_flush();

        $offset = 0;
        $limit = 3;
        $sizeData /= $limit;

        // Init IPC connection
        $server = stream_socket_server("tcp://127.0.0.1:8000", $errno, $errorMessage);
        if ($server === false) {
            throw new UnexpectedValueException("Could not bind to socket: $errorMessage");
        }

        for( $i = 0; $i < $sizeData; $i++)
        {
            // Check our socket for data
            $client = @stream_socket_accept($server);
            if ($client) {
                // Read sent data
                $data = fread($client, 1024);

                // Probably break
                if ($data === 'stop') {
                    break;
                }
            }

            $offset += $limit;
            var_dump($offset);
        }
        // Close socket after sending all messages
        fclose($client);
    }

StopAction :

public function stopAction()
{
    $socket = stream_socket_client('tcp://127.0.0.1:8000');
    fwrite($socket, 'stop');
    fclose($socket);

}

But the problem here, is that the port must be changed for every socket, & can't use many sockets at time.. and also it's taking much time to execute ! an other question : Is there any possibility to create a simple txt file instead?

  • 写回答

1条回答 默认 最新

  • dousha4804 2016-02-18 12:06
    关注

    you can use the EventEmitter extension,download it from github https://github.com/christopherobin/EventEmitter

    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀