<s id="cdxes"></s>
    <meter id="cdxes"><td id="cdxes"><ol id="cdxes"></ol></td></meter>
  • \n\n    \n        {{--對話窗口頭部--}}\n        
    \n            \n                \"workermanheading}}\" width=\"80px\" height=\"40px\">\n            <\/div>\n            \n                {{$to->name}}\n            <\/div>\n        <\/div>\n        {{--\/\/對話窗口內容--}}\n        \n            {{--對方的頭像與文字--}}\n            {{----}}\n                {{----}}\n                    {{--\"workermanheading}}\" width=\"50px\" height=\"50px\">--}}\n                {{--<\/div>--}}\n                {{--dsadsadsadsadsa<\/div>--}}\n            {{--<\/div>--}}\n            {{--我的頭像與文字--}}\n            {{----}}\n                {{----}}\n                    {{--\"workermanheading}}\" width=\"50px\" height=\"50px\">--}}\n                {{--<\/div>--}}\n                {{--dsadsadsadsadsa<\/div>--}}\n            {{--<\/div>--}}\n        <\/div>\n        {{--對話發(fā)送窗口--}}\n        \n            id}}\">\n            id}}\">\n            \n            \n            <\/textarea>\n            
    \n                \n                發(fā)表<\/button>\n            <\/div>\n        <\/form>\n        房間號{{$room}}\n    <\/div>\n<\/div>\n<\/body>\n<\/html>\n

    亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

    Home PHP Framework Workerman workerman combines laravel to develop online chat application

    workerman combines laravel to develop online chat application

    Nov 22, 2019 pm 02:18 PM
    workerman

    下面由workerman php教程欄目給大家介紹workerman結合laravel開發(fā)在線聊天應用的方法,希望對需要的朋友有所幫助!

    workerman combines laravel to develop online chat application

    項目背景:

    最近由于公司的業(yè)務需求,需要用到聊天功能。而且有比較多的個性化需求需要定制。之前使用別人的聊天組件是基于微擎的。如果要移植到普通的H5在邏輯修改還有定制上存在比較多的困難。為此只能克服困難,自己搭建一個吧

    什么是Workerman?

    Workerman是一款開源高性能異步PHP socket即時通訊框架。支持高并發(fā),超高穩(wěn)定性,被廣泛的用于手機app、移動通訊,微信小程序,手游服務端、網絡游戲、PHP聊天室、硬件通訊、智能家居、車聯網、物聯網等領域的開發(fā)。?

    支持TCP長連接,支持Websocket、HTTP等協(xié)議,支持自定義協(xié)議。擁有異步Mysql、異步Redis、異步Http、MQTT物聯網客戶端、異步消息隊列等眾多高性能組件。

    開始實戰(zhàn)吧!

    1.第一步我們先把workerman里需要用到的擴展composer下來吧

    "workerman/gateway-worker": "^3.0",
    "workerman/gatewayclient": "^3.0",
    "workerman/workerman": "^3.5",

    2.第二步我們到官方網站把demo全部下載下來,然后放到我們項目中的目錄圖片中我就把整個項目都放在了HTTP/Controller/Workerman中。

    workerman combines laravel to develop online chat application

    3.第三步我們需要把把以下3個文件的引用部分修改為以下。

    不然會報路徑錯誤

    start_businessworker,start_gateway,start_register
    require_once __DIR__ . &#39;/../../../../../vendor/autoload.php&#39;;

    4.修改完成后我們就可以在liunx直接運行對應的啟動文件

    php start.php start -d
    如果你是在window下就雙擊start_for_win.bat運行

    5.運行成功后,你就應該可以看到以下的界面到此我們搭建基于workerman的通信環(huán)境就已經完成。

    接下來我們就可以根據自己的項目需求進行開發(fā)。

    在此向大家重點說明。

    我們所有的聊天是邏輯都在目錄中的Events.php進行修改。


    下面我給大家貼一下我編寫的部分代碼。

    Event.php

    <?php
    /**
     * This file is part of workerman.
     *
     * Licensed under The MIT License
     * For full copyright and license information, please see the MIT-LICENSE.txt
     * Redistributions of files must retain the above copyright notice.
     *
     * @author walkor<walkor@workerman.net>
     * @copyright walkor<walkor@workerman.net>
     * @link http://www.workerman.net/
     * @license http://www.opensource.org/licenses/mit-license.php MIT License
     */
    /**
     * 用于檢測業(yè)務代碼死循環(huán)或者長時間阻塞等問題
     * 如果發(fā)現業(yè)務卡死,可以將下面declare打開(去掉//注釋),并執(zhí)行php start.php reload
     * 然后觀察一段時間workerman.log看是否有process_timeout異常
     */
    //declare(ticks=1);
    /**
     * 聊天主邏輯
     * 主要是處理 onMessage onClose
     */
    use \GatewayWorker\Lib\Gateway;
    class Events
    {
        /**
         * 作者:何志偉
         * 當客戶端連接上來的時候
         * 創(chuàng)建時間:2018/10/25
         * @param $client_id 此ID為gatewayworker 自動生成ID
         */
        public static function onConnect($client_id)
        {
            Gateway::sendToClient($client_id, json_encode(array(
                &#39;type&#39;      => &#39;init&#39;,
                &#39;client_id&#39; => $client_id
            )));
        }
        /**
         * 有消息時
         * @param int $client_id
         * @param mixed $message
         */
        public static function onMessage($client_id, $message)
        {
            // debug
            echo "client:{$_SERVER[&#39;REMOTE_ADDR&#39;]}:{$_SERVER[&#39;REMOTE_PORT&#39;]} gateway:{$_SERVER[&#39;GATEWAY_ADDR&#39;]}:{$_SERVER[&#39;GATEWAY_PORT&#39;]}  client_id:$client_id session:".json_encode($_SESSION)." onMessage:".$message."\n";
            // 客戶端傳遞的是json數據
            $message_data = json_decode($message, true);
            if(!$message_data)
            {
                return ;
            }
            // 根據類型執(zhí)行不同的業(yè)務
            switch($message_data[&#39;type&#39;])
            {
                // 客戶端回應服務端的心跳
                case &#39;pong&#39;:
                    return;
                // 客戶端登錄 message格式: {type:login, name:xx, room_id:1} ,添加到客戶端,廣播給所有客戶端xx進入聊天室
                case &#39;login&#39;:
                    // 判斷是否有房間號
                    if(!isset($message_data[&#39;room_id&#39;]))
                    {
                        throw new \Exception("\$message_data[&#39;room_id&#39;] not set. client_ip:{$_SERVER[&#39;REMOTE_ADDR&#39;]} \$message:$message");
                    }
                    // 把房間號昵稱放到session中
                    $room_id = $message_data[&#39;room_id&#39;];
                    $client_name = htmlspecialchars($message_data[&#39;client_name&#39;]);
                    $_SESSION[&#39;room_id&#39;] = $room_id;
                    $_SESSION[&#39;client_name&#39;] = $client_name;
                    // 獲取房間內所有用戶列表
                    $clients_list = Gateway::getClientSessionsByGroup($room_id);
                    foreach($clients_list as $tmp_client_id=>$item)
                    {
                        $clients_list[$tmp_client_id] = $item[&#39;client_name&#39;];
                    }
    //                $clients_list[$client_id] = $client_name;
                    // 轉播給當前房間的所有客戶端,xx進入聊天室 message {type:login, client_id:xx, name:xx}
                    $new_message = array(&#39;type&#39;=>$message_data[&#39;type&#39;], &#39;client_id&#39;=>$client_id, &#39;client_name&#39;=>htmlspecialchars($client_name), &#39;time&#39;=>date(&#39;Y-m-d H:i:s&#39;),&#39;to&#39;=>$message_data[&#39;to&#39;],&#39;room_id&#39;=>$message_data[&#39;room_id&#39;],
                        &#39;from&#39;=>$message_data[&#39;from&#39;],&#39;tag&#39;=>$message_data[&#39;tag&#39;]);
                    Gateway::sendToGroup($room_id, json_encode($new_message));
                    Gateway::joinGroup($client_id, $room_id);
                    // 給當前用戶發(fā)送用戶列表
                    $new_message[&#39;client_list&#39;] = $clients_list;
                    Gateway::sendToCurrentClient(json_encode($new_message));
                    return;
                // 客戶端發(fā)言 message: {type:say, to_client_id:xx, content:xx}
                case &#39;say&#39;:
                    // 非法請求
                    if(!isset($_SESSION[&#39;room_id&#39;]))
                    {
                        throw new \Exception("\$_SESSION[&#39;room_id&#39;] not set. client_ip:{$_SERVER[&#39;REMOTE_ADDR&#39;]}");
                    }
                    $room_id = $_SESSION[&#39;room_id&#39;];
                    $client_name = $_SESSION[&#39;client_name&#39;];
                    // 私聊
    //                if($message_data[&#39;to_client_id&#39;] != &#39;all&#39;)
    //                {
    //                    $new_message = array(
    //                        &#39;type&#39;=>&#39;say&#39;,
    //                        &#39;from_client_id&#39;=>$client_id,
    //                        &#39;from_client_name&#39; =>$client_name,
    //                        &#39;to_client_id&#39;=>$message_data[&#39;to_client_id&#39;],
    //                        &#39;content&#39;=>"<b>對你說: </b>".nl2br(htmlspecialchars($message_data[&#39;content&#39;])),
    //                        &#39;time&#39;=>date(&#39;Y-m-d H:i:s&#39;),
    //                    );
    //                    Gateway::sendToClient($message_data[&#39;to_client_id&#39;], json_encode($new_message));
    //                    $new_message[&#39;content&#39;] = "<b>你對".htmlspecialchars($message_data[&#39;to_client_name&#39;])."說: </b>".nl2br(htmlspecialchars($message_data[&#39;content&#39;]));
    //                    return Gateway::sendToCurrentClient(json_encode($new_message));
    //                }
                    $new_message = array(
                        &#39;type&#39;=>&#39;say&#39;,
                        &#39;from_client_id&#39;=>$client_id,
                        &#39;from_client_name&#39; =>$client_name,
                        &#39;to_client_id&#39;=>&#39;all&#39;,
                        &#39;content&#39;=>nl2br(htmlspecialchars($message_data[&#39;content&#39;])),
                        &#39;time&#39;=>date(&#39;Y-m-d H:i:s&#39;),
                    );
                    return Gateway::sendToGroup($room_id ,json_encode($new_message));
            }
        }
        /**
         * 當客戶端斷開連接時
         * @param integer $client_id 客戶端id
         */
        public static function onClose($client_id)
        {
            // debug
            echo "client:{$_SERVER[&#39;REMOTE_ADDR&#39;]}:{$_SERVER[&#39;REMOTE_PORT&#39;]} gateway:{$_SERVER[&#39;GATEWAY_ADDR&#39;]}:{$_SERVER[&#39;GATEWAY_PORT&#39;]}  client_id:$client_id onClose:&#39;&#39;\n";
            // 從房間的客戶端列表中刪除
            if(isset($_SESSION[&#39;room_id&#39;]))
            {
                $room_id = $_SESSION[&#39;room_id&#39;];
                $new_message = array(&#39;type&#39;=>&#39;logout&#39;, &#39;from_client_id&#39;=>$client_id, &#39;from_client_name&#39;=>$_SESSION[&#39;client_name&#39;], &#39;time&#39;=>date(&#39;Y-m-d H:i:s&#39;));
                Gateway::sendToGroup($room_id, json_encode($new_message));
            }
        }
    }

    客戶端頁面

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="UTF-8">
        <title>與{{$to->name}}的對話</title>
        <script type="text/javascript" src="{{asset(&#39;js&#39;)}}/swfobject.js"></script>
        <script type="text/javascript" src="{{asset(&#39;js&#39;)}}/web_socket.js"></script>
        <script type="text/javascript" src="{{asset(&#39;js&#39;)}}/jquery.min.js"></script>
        <link href="{{asset(&#39;css&#39;)}}/jquery-sinaEmotion-2.1.0.min.css" rel="stylesheet">
        <link href="{{asset(&#39;css&#39;)}}/bootstrap.min.css" rel="stylesheet">
        <link href="{{asset(&#39;css&#39;)}}/style.css" rel="stylesheet">
        <script type="text/javascript" src="{{asset(&#39;js&#39;)}}/jquery-sinaEmotion-2.1.0.min.js"></script>
        {{--<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>--}}
    </head>
    <style>
        #sinaEmotion {
            z-index: 999;
            width: 373px;
            padding: 10px;
            display: none;
            font-size: 12px;
            background: #fff;
            overflow: hidden;
            position: absolute;
            border: 1px solid #e8e8e8;
            top: 100px;
            left: 542.5px;
        }
    </style>
    <body onload="connect();" style="margin: auto; text-align: center;">
    <div style="margin: auto;">
        <div style="border: 1px solid red; height: 40px; width: 500px; margin: auto;">
            {{--對話窗口頭部--}}
            <div>
                <div style="width: 80px; height: 40px; border: 1px solid blue; float: left">
                    <img  src="/static/imghw/default1.png"  data-src="{{$to- alt="workerman combines laravel to develop online chat application" >heading}}"  class="lazy"   width="80px" height="40px">
                </div>
                <div style="width: 150px; height: 40px; border: 1px solid blue; float: left">
                    {{$to->name}}
                </div>
            </div>
            {{--//對話窗口內容--}}
            <div style="width: 500px; height: 400px; border: 1px solid green; margin-top: 40px; overflow-y: auto">
                {{--對方的頭像與文字--}}
                {{--<div style="min-height: 50px;margin-top: 10px;">--}}
                    {{--<div style="width: 50px;height: 50px; border: 1px solid red;  margin-left:10px; float: left">--}}
                        {{--<img  src="/static/imghw/default1.png"  data-src="{{$to- alt="workerman combines laravel to develop online chat application" >heading}}"  class="lazy"   width="50px" height="50px">--}}
                    {{--</div>--}}
                    {{--<div style="border: 1px solid red; float: left;  min-height: 50px" >dsadsadsadsadsa</div>--}}
                {{--</div>--}}
                {{--我的頭像與文字--}}
                {{--<div style= "min-height:50px;margin-top: 10px;">--}}
                    {{--<div style="width: 50px;height: 50px; border: 1px solid red;  margin-left:10px; float: right">--}}
                        {{--<img  src="/static/imghw/default1.png"  data-src="{{$from- alt="workerman combines laravel to develop online chat application" >heading}}"  class="lazy"   width="50px" height="50px">--}}
                    {{--</div>--}}
                    {{--<div style="border: 1px solid red; float: right;  min-height: 50px" >dsadsadsadsadsa</div>--}}
                {{--</div>--}}
            </div>
            {{--對話發(fā)送窗口--}}
            <form onsubmit="return onSubmit(); return false;" id="ajaxfrom">
                <input type="hidden" name="to" value="{{$to->id}}">
                <input type="hidden" name="from" value="{{$from->id}}">
                <input type="hidden" name="room_id" value="{{$room}}">
                <input type="hidden" name="tag" value="{{$tag}}">
                <textarea id="textarea" name="content" style="margin: 0px; width: 501px; height: 213px;"></textarea>
                <div>
                    <input type="button" class="btn btn-default face pull-left" value="表情" />
                    <button type="submit" class="btn btn-default">發(fā)表</button>
                </div>
            </form>
            房間號{{$room}}
        </div>
    </div>
    </body>
    </html>
    <script type="text/javascript">
        if (typeof console == "undefined") {    this.console = { log: function (msg) {  } };}
        // 如果瀏覽器不支持websocket,會使用這個flash自動模擬websocket協(xié)議,此過程對開發(fā)者透明
        WEB_SOCKET_SWF_LOCATION = "/swf/WebSocketMain.swf";
        // 開啟flash的websocket debug
        WEB_SOCKET_DEBUG = true;
        var ws, name, client_list={};
        var to_client_id="";
        // 連接服務端初始化函數
        function connect() {
            // 創(chuàng)建websocket 屆時可以替換為對應的服務器地址
            ws = new WebSocket("ws://"+document.domain+":7272");
            // 當socket連接打開時,輸入用戶名
            ws.onopen = onopen;
            // 當有消息時根據消息類型顯示不同信息
            ws.onmessage = onmessage;
            //當連接丟失時,調用連接方法嘗試重新連接
            ws.onclose = function() {
                console.log("連接關閉,定時重連");
                connect();
            };
            //當操作報錯時,返回異常錯誤
            ws.onerror = function() {
                console.log("出現錯誤");
            };
            //發(fā)送ajax獲取當前房間的通話記錄
            $.post("/get_record", { "room":"{{$room}}" },
                function(msg){
                    $.each(msg,function (v,k) {
                        console.log(k);
                        //判斷
                        if(k.tag!="{{$tag}}"){
                            $(".content").append(
                                &#39;<div style="min-height: 50px;margin-top: 10px;">&#39; +
                                &#39;<div style="width: 50px;height: 50px; border: 1px solid red;  margin-left:10px; float: left">&#39;+
                                &#39;<img  src="/static/imghw/default1.png"  data-src="{{$to- alt="workerman combines laravel to develop online chat application" >heading}}"  class="lazy"   width="50px" height="50px">&#39;+
                                &#39;</div>&#39;+
                                &#39;<div style="border: 1px solid red; float: left;  min-height: 50px" >&#39;+k.content+&#39;</div>&#39;+
                                &#39;<div>&#39;
                            ).parseEmotion();
                        }else{
                            $(".content").append(
                                &#39;<div style="min-height: 50px;margin-top: 10px;">&#39; +
                                &#39;<div style="width: 50px;height: 50px; border: 1px solid red;  margin-left:10px; float: right">&#39;+
                                &#39;<img  src="/static/imghw/default1.png"  data-src="{{$from- alt="workerman combines laravel to develop online chat application" >heading}}"  class="lazy"   width="50px" height="50px">&#39;+
                                &#39;</div>&#39;+
                                &#39;<div style="border: 1px solid red; float: right;  min-height: 50px" >&#39;+k.content+&#39;</div>&#39;+
                                &#39;<div>&#39;
                            ).parseEmotion();
                        }
                    })
                });
        }
        // 連接建立時發(fā)送登錄信息
        function onopen()
        {
            var login_data=&#39;{"type":"login","client_name":"{{$from->name}}","room_id":"{{$room}}","to":"{{$to->id}}","from":"{{$from->id}}","tag":"{{$tag}}"}&#39;;
            ws.send(login_data);
            console.log(&#39;登錄成功&#39;)
        }
        // 服務端發(fā)來消息時
        function onmessage(e)
        {
            var data = JSON.parse(e.data);
            switch(data[&#39;type&#39;]){
                // 服務端ping客戶端心跳
                case &#39;ping&#39;:
                    ws.send(&#39;{"type":"pong"}&#39;);
                    break;
                // 登錄 更新用戶列表
                case &#39;login&#39;:
                    //講需要的發(fā)送ID保存到本地to_client_id變量中
                    for(var p in data[&#39;client_list&#39;]){
                        to_client_id=p;
                    }
                    console.log(to_client_id);
                    break;
                // 發(fā)言
                case &#39;say&#39;:
                    console.log(data);
                    say(data[&#39;from_client_id&#39;], data[&#39;from_client_name&#39;], data[&#39;content&#39;], data[&#39;time&#39;]);
                    break;
                // 用戶退出 更新用戶列表
                case &#39;logout&#39;:
                    console.log(data);
                    break;
                case &#39;init&#39;:
                    //此處可以發(fā)送ajax用于綁定不同的用戶ID和client
                    console.log(data);
                    break;
            }
        }
        // 提交對話
        function onSubmit() {
            //先檢查當前的對話是否超過20條記錄數
            var count=true;
            //發(fā)送ajax獲取當前房間的通話記錄
            $.ajax({
                url: "/check_count",
                type: "post",
                async:false,
                // cache: false,
                // contentType: false,
                // processData: false,
                data:{
                &#39;room&#39;:"1",
                },
                success: function (msg) {
                    if(msg>10){
                        alert(&#39;當前的對話已經超過次數,請購買對應服務&#39;)
                        count=false;
                    }
                }
            });
            if(count){
                var neirong=$("#textarea").val().replace(/"/g, &#39;\\"&#39;).replace(/\n/g,&#39;\\n&#39;).replace(/\r/g, &#39;\\r&#39;);
                //ajax先把對應的內容發(fā)送到后臺錄入,回調成功后才把信息發(fā)送
                var fm=$("#ajaxfrom")[0];
                var formData = new FormData(fm);
                $.ajax({
                    url: "/record",
                    type: "post",
                    cache: false,
                    contentType: false,
                    processData: false,
                    data: formData,
                    beforeSend:function(){
                    },
                    success: function (msg) {
                        if(msg.code=="0"){
                            ws.send(&#39;{"type":"say","to_client_id":"all","to_client_name":"{{$to->name}}","content":"&#39;+neirong+&#39;"}&#39;);
                            //清空文本框內容
                            $("#textarea").val("");
                            //強制定位光標
                            $("#textarea").focus();
                        }else{
                        }
                    }
                });
            }
            return false;
        }
        // 發(fā)言
        function say(from_client_id, from_client_name, content, time){
            //判斷當前的用戶名稱與發(fā)送消息的名稱是否一致
            if( "{{$from->name}}" == from_client_name){
                $(".content").append(
                    &#39;<div style="min-height: 50px;margin-top: 10px;">&#39; +
                    &#39;<div style="width: 50px;height: 50px; border: 1px solid red;  margin-left:10px; float: right">&#39;+
                    &#39;<img  src="/static/imghw/default1.png"  data-src="{{$from- alt="workerman combines laravel to develop online chat application" >heading}}"  class="lazy"   width="50px" height="50px">&#39;+
                    &#39;</div>&#39;+
                    &#39;<div style="border: 1px solid red; float: right;  min-height: 50px" >&#39;+content+&#39;</div>&#39;+
                    &#39;<div>&#39;
                ).parseEmotion();
            }else{
                $(".content").append(
                    &#39;<div style="min-height: 50px;margin-top: 10px;">&#39; +
                    &#39;<div style="width: 50px;height: 50px; border: 1px solid red;  margin-left:10px; float: left">&#39;+
                    &#39;<img  src="/static/imghw/default1.png"  data-src="{{$to- alt="workerman combines laravel to develop online chat application" >heading}}"  class="lazy"   width="50px" height="50px">&#39;+
                    &#39;</div>&#39;+
                    &#39;<div style="border: 1px solid red; float: left;  min-height: 50px" >&#39;+content+&#39;</div>&#39;+
                    &#39;<div>&#39;
                ).parseEmotion();
            }
            // $("#dialog").append(&#39;<div><img  src="/static/imghw/default1.png"  data-src="http://lorempixel.com/38/38/?&#39;+from_client_id+&#39;"  class="lazy"   / alt="workerman combines laravel to develop online chat application" > &#39;+from_client_name+&#39; <br> &#39;+time+&#39;<div   style="max-width:90%"></div><p class="triangle-isosceles top">&#39;+content+&#39;</p> </div>&#39;).parseEmotion();
        }
        $(function(){
            //全局用戶ID
            select_client_id = &#39;all&#39;;
            //如果發(fā)送的用戶有變化則對應的用戶ID進行替換
            $("#client_list").change(function(){
                select_client_id = $("#client_list option:selected").attr("value");
            });
            //表情選擇
            $(&#39;.face&#39;).click(function(event){
                $(this).sinaEmotion();
                event.stopPropagation();
            });
        });
        // document.write(&#39;<meta name="viewport" content="width=device-width,initial-scale=1">&#39;);
        $("textarea").on("keydown", function(e) {
            //按enter鍵自動提交
            if(e.keyCode === 13 && !e.ctrlKey) {
                e.preventDefault();
                $(&#39;form&#39;).submit();
                return false;
            }
            // 按ctrl+enter組合鍵換行
            if(e.keyCode === 13 && e.ctrlKey) {
                $(this).val(function(i,val){
                    return val + "\n";
                });
            }
        });
    </script>

    復制代碼這兩個代碼片段其實就是主要運行的核心片段。其他框架的自帶參數需要各位自己去根據文檔去調試優(yōu)化。到此基于workerman的聊天用于功能demo已經搭建完畢。

    The above is the detailed content of workerman combines laravel to develop online chat application. For more information, please follow other related articles on the PHP Chinese website!

    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    Hot Topics

    PHP Tutorial
    1488
    72
    Implement file upload and download in Workerman documents Implement file upload and download in Workerman documents Nov 08, 2023 pm 06:02 PM

    To implement file upload and download in Workerman documents, specific code examples are required. Introduction: Workerman is a high-performance PHP asynchronous network communication framework that is simple, efficient, and easy to use. In actual development, file uploading and downloading are common functional requirements. This article will introduce how to use the Workerman framework to implement file uploading and downloading, and give specific code examples. 1. File upload: File upload refers to the operation of transferring files on the local computer to the server. The following is used

    Which one is better, swoole or workerman? Which one is better, swoole or workerman? Apr 09, 2024 pm 07:00 PM

    Swoole and Workerman are both high-performance PHP server frameworks. Known for its asynchronous processing, excellent performance, and scalability, Swoole is suitable for projects that need to handle a large number of concurrent requests and high throughput. Workerman offers the flexibility of both asynchronous and synchronous modes, with an intuitive API that is better suited for ease of use and projects that handle lower concurrency volumes.

    How to implement the basic usage of Workerman documents How to implement the basic usage of Workerman documents Nov 08, 2023 am 11:46 AM

    Introduction to how to implement the basic usage of Workerman documents: Workerman is a high-performance PHP development framework that can help developers easily build high-concurrency network applications. This article will introduce the basic usage of Workerman, including installation and configuration, creating services and listening ports, handling client requests, etc. And give corresponding code examples. 1. Install and configure Workerman. Enter the following command on the command line to install Workerman: c

    How to implement the timer function in the Workerman document How to implement the timer function in the Workerman document Nov 08, 2023 pm 05:06 PM

    How to implement the timer function in the Workerman document Workerman is a powerful PHP asynchronous network communication framework that provides a wealth of functions, including the timer function. Use timers to execute code within specified time intervals, which is very suitable for application scenarios such as scheduled tasks and polling. Next, I will introduce in detail how to implement the timer function in Workerman and provide specific code examples. Step 1: Install Workerman First, we need to install Worker

    How to implement the reverse proxy function in the Workerman document How to implement the reverse proxy function in the Workerman document Nov 08, 2023 pm 03:46 PM

    How to implement the reverse proxy function in the Workerman document requires specific code examples. Introduction: Workerman is a high-performance PHP multi-process network communication framework that provides rich functions and powerful performance and is widely used in Web real-time communication and long connections. Service scenarios. Among them, Workerman also supports the reverse proxy function, which can realize load balancing and static resource caching when the server provides external services. This article will introduce how to use Workerman to implement the reverse proxy function.

    Workerman development: How to implement real-time video calls based on UDP protocol Workerman development: How to implement real-time video calls based on UDP protocol Nov 08, 2023 am 08:03 AM

    Workerman development: real-time video call based on UDP protocol Summary: This article will introduce how to use the Workerman framework to implement real-time video call function based on UDP protocol. We will have an in-depth understanding of the characteristics of the UDP protocol and show how to build a simple but complete real-time video call application through code examples. Introduction: In network communication, real-time video calling is a very important function. The traditional TCP protocol may have problems such as transmission delays when implementing high-real-time video calls. And UDP

    How to use Workerman to build a high-availability load balancing system How to use Workerman to build a high-availability load balancing system Nov 07, 2023 pm 01:16 PM

    How to use Workerman to build a high-availability load balancing system requires specific code examples. In the field of modern technology, with the rapid development of the Internet, more and more websites and applications need to handle a large number of concurrent requests. In order to achieve high availability and high performance, the load balancing system has become one of the essential components. This article will introduce how to use the PHP open source framework Workerman to build a high-availability load balancing system and provide specific code examples. 1. Introduction to Workerman Worke

    Implement the file transfer function in Workerman documents Implement the file transfer function in Workerman documents Nov 08, 2023 pm 03:39 PM

    Workerman is a high-performance asynchronous event-driven framework developed based on PHP. It can easily realize the development of long connections under the TCP/UDP protocol. In addition, Workerman also provides the function of realizing file transfer, which can be used in scenarios such as large file transfer and data backup. This article will introduce how to implement the file transfer function in Workerman and provide specific code examples. 1. File upload function To implement the file upload function, the client needs to send the file to be uploaded to the server, and the server verifies

    See all articles