在Laravel项目中集成PHP套接字

I'm working on a project module similer to instagram story section. Other Users are going to upload stories (Text/Video/images) and logged user can watch the stories of other users. and a user can post multiple stories. In order to update the seen status of story which user have already watched like instagram if a user have already watched the stories and user uploads some new stories which are completely new to user previours already viewed stories should disapper and new wil be seen. For sending real-time story seen status I want to use sockets to send the status of story.

Can someone tell me how to integrate PHP sockets in my Laravel project code. I tried to do this by following all the steps given in this tutorial but my page keeps on loading when I run server script written on my view.

I've seen also php manual.

I need to do this only using php sockets only as per requirements !

routes.api.php :

Route::get('server', 'API\NotificationController@storySeen');
Route::post('server-post', 'API\NotificationController@serverPost')->name('server.post');
Route::get('client', 'API\NotificationController@client');

API\UserProfileController.php :

public function storySeen()
{
    return view('server');
}

public function serverPost(Request $request)
{
    $serverReply = $request->input('reply');
    $host = "localhost";
    $port = 8189;

    // No Timeout
    set_time_limit(10);
    $socket = socket_create(AF_INET, SOCK_STREAM, 0) or dd("Could not create socket
");
    $result = socket_bind($socket, $host, $port) or dd("Could not bind to socket
");
    $result = socket_listen($socket, 3) or dd("Could not set up socket listener
");
    $spawn = socket_accept($socket) or dd("Could not accept incoming connection
");
    $input = socket_read($spawn, 1024) or dd("Could not read input
");

    $output = strrev($input) . "
";
    $mg = trim($output);
    $client = "Client says : \t" . $mg;
    socket_write($spawn, $client, strlen($client)) or dd("Could not write output
");
    socket_close($spawn);
    socket_close($socket);

    return view('server', ['client' => $client]);
}

public function client()
{
    return view('test');
}

resources\views\server.blade.php :

<div class="flex-center position-ref full-height">
    <div class="content">
        <form method="POST" action="{{route('server.post')}}" enctype="multipart/form-data">
            {{csrf_field()}}
            <table>
                <tr>
                    <label>Enter message:</label>
                    <input type="text" name="reply">
                    <input type="submit" name="btnSend" value="Send">
                </tr>
                <?php
                //                if (isset($_GET['btnSend']))
                //                {
                //                    $host ="192.168.1.109";
                //                    $port = 20205;
                //
                //                    $msg  = $_REQUEST['txtMessage'];
                //                    $sock  = socket_create(AF_INET, SOCK_STREAM,0)  or die("Could not create");
                //                    socket_connect($sock, $host, $port)  or die("Could not Connect");
                //                    socket_write($sock, $msg, strlen($msg))  or die("Could not write");
                //                    $reply = socket_read($sock,1024);
                //                    $reply = trim($reply);
                //                        $reply= "Server says : \t" . $reply;
                //                }
                //                ?>
                <tr>
                    <td>
                        <textarea rows="10" col="30"> {{isset($client)?$client:''}}</textarea>
                    </td>
                </tr>
            </table>
        </form>

        <div class="links">

        </div>
    </div>
</div>

resources\views\test.blade.php :

<form method="GET" enctype="multipart/form-data">
    {{csrf_field()}}
    <table>
        <tr>
            <label>Enter message:</label>
            <input type="text" name="txtClient">
            <input type="submit" name="btnSend" value="Send">
        </tr>
        <?php
        if (isset($_GET['btnSend'])) {
            $host = "localhost";
            $port = 8189;

            $msg = $_REQUEST['txtClient'];
            $sock = socket_create(AF_INET, SOCK_STREAM, 0) or dd("Could not create");
            socket_bind($sock, $host, $port) or dd("Could not Connect");
            //socket_connect($sock, $host, $port)  or dd("Could not Connect");
            socket_write($sock, $msg, strlen($msg)) or dd("Could not write");
            $reply = socket_read($sock, 1024);
            $reply = trim($reply);
            $reply = "Server says : \t" . $reply;
            socket_close($sock);

        }
        ?>
        <tr>
            <td>
                <textarea rows="10" col="30"> {{isset($reply)?$reply:''}}</textarea>
            </td>
        </tr>
    </table>
</form>

My page keeps on loading when I run server script. And on retrying it shows.

Can not bind as port is already in use.

and when I run client script there is error message :

Broken Pipe