\n\n    \n        {{--對話窗口頭部--}}\n        
\n            \n                heading}}\" width=\"80px\" height=\"40px\">\n            <\/div>\n            \n                {{$to->name}}\n            <\/div>\n        <\/div>\n        {{--\/\/對話窗口內(nèi)容--}}\n        \n            {{--對方的頭像與文字--}}\n            {{----}}\n                {{----}}\n                    {{--heading}}\" width=\"50px\" height=\"50px\">--}}\n                {{--<\/div>--}}\n                {{--dsadsadsadsadsa<\/div>--}}\n            {{--<\/div>--}}\n            {{--我的頭像與文字--}}\n            {{----}}\n                {{----}}\n                    {{--heading}}\" 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国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

首頁 php框架 Workerman workerman結(jié)合laravel開發(fā)在線聊天應(yīng)用

workerman結(jié)合laravel開發(fā)在線聊天應(yīng)用

Nov 22, 2019 pm 02:18 PM
workerman

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

workerman結(jié)合laravel開發(fā)在線聊天應(yīng)用

項目背景:

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

什么是Workerman

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

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

開始實戰(zhàn)吧!

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

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

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

dce98368acab534059e8f0d5de08bd7.png

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

不然會報路徑錯誤

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

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

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

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

接下來我們就可以根據(jù)自己的項目需求進行開發(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è)務(wù)代碼死循環(huán)或者長時間阻塞等問題
 * 如果發(fā)現(xiàn)業(yè)務(wù)卡死,可以將下面declare打開(去掉//注釋),并執(zhí)行php start.php reload
 * 然后觀察一段時間workerman.log看是否有process_timeout異常
 */
//declare(ticks=1);
/**
 * 聊天主邏輯
 * 主要是處理 onMessage onClose
 */
use \GatewayWorker\Lib\Gateway;
class Events
{
    /**
     * 作者:何志偉
     * 當(dāng)客戶端連接上來的時候
     * 創(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數(shù)據(jù)
        $message_data = json_decode($message, true);
        if(!$message_data)
        {
            return ;
        }
        // 根據(jù)類型執(zhí)行不同的業(yè)務(wù)
        switch($message_data[&#39;type&#39;])
        {
            // 客戶端回應(yīng)服務(wù)端的心跳
            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;
                // 獲取房間內(nèi)所有用戶列表
                $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;
                // 轉(zhuǎn)播給當(dāng)前房間的所有客戶端,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);
                // 給當(dāng)前用戶發(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));
        }
    }
    /**
     * 當(dāng)客戶端斷開連接時
     * @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="{{$to->heading}}" width="80px" height="40px">
            </div>
            <div style="width: 150px; height: 40px; border: 1px solid blue; float: left">
                {{$to->name}}
            </div>
        </div>
        {{--//對話窗口內(nèi)容--}}
        <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="{{$to->heading}}" 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="{{$from->heading}}" 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="";
    // 連接服務(wù)端初始化函數(shù)
    function connect() {
        // 創(chuàng)建websocket 屆時可以替換為對應(yīng)的服務(wù)器地址
        ws = new WebSocket("ws://"+document.domain+":7272");
        // 當(dāng)socket連接打開時,輸入用戶名
        ws.onopen = onopen;
        // 當(dāng)有消息時根據(jù)消息類型顯示不同信息
        ws.onmessage = onmessage;
        //當(dāng)連接丟失時,調(diào)用連接方法嘗試重新連接
        ws.onclose = function() {
            console.log("連接關(guān)閉,定時重連");
            connect();
        };
        //當(dāng)操作報錯時,返回異常錯誤
        ws.onerror = function() {
            console.log("出現(xiàn)錯誤");
        };
        //發(fā)送ajax獲取當(dāng)前房間的通話記錄
        $.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="{{$to->heading}}" 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="{{$from->heading}}" 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;)
    }
    // 服務(wù)端發(fā)來消息時
    function onmessage(e)
    {
        var data = JSON.parse(e.data);
        switch(data[&#39;type&#39;]){
            // 服務(wù)端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() {
        //先檢查當(dāng)前的對話是否超過20條記錄數(shù)
        var count=true;
        //發(fā)送ajax獲取當(dāng)前房間的通話記錄
        $.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;當(dāng)前的對話已經(jīng)超過次數(shù),請購買對應(yīng)服務(wù)&#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先把對應(yīng)的內(nèi)容發(fā)送到后臺錄入,回調(diào)成功后才把信息發(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;);
                        //清空文本框內(nèi)容
                        $("#textarea").val("");
                        //強制定位光標
                        $("#textarea").focus();
                    }else{
                    }
                }
            });
        }
        return false;
    }
    // 發(fā)言
    function say(from_client_id, from_client_name, content, time){
        //判斷當(dāng)前的用戶名稱與發(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="{{$from->heading}}" 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="{{$to->heading}}" 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="http://lorempixel.com/38/38/?&#39;+from_client_id+&#39;" /> &#39;+from_client_name+&#39; <br> &#39;+time+&#39;<div style="clear:both;"></div><p class="triangle-isosceles top">&#39;+content+&#39;</p> </div>&#39;).parseEmotion();
    }
    $(function(){
        //全局用戶ID
        select_client_id = &#39;all&#39;;
        //如果發(fā)送的用戶有變化則對應(yīng)的用戶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>

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

以上是workerman結(jié)合laravel開發(fā)在線聊天應(yīng)用的詳細內(nèi)容。更多信息請關(guān)注PHP中文網(wǎng)其他相關(guān)文章!

本站聲明
本文內(nèi)容由網(wǎng)友自發(fā)貢獻,版權(quán)歸原作者所有,本站不承擔(dān)相應(yīng)法律責(zé)任。如您發(fā)現(xiàn)有涉嫌抄襲侵權(quán)的內(nèi)容,請聯(lián)系admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費脫衣服圖片

Undresser.AI Undress

Undresser.AI Undress

人工智能驅(qū)動的應(yīng)用程序,用于創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用于從照片中去除衣服的在線人工智能工具。

Clothoff.io

Clothoff.io

AI脫衣機

Video Face Swap

Video Face Swap

使用我們完全免費的人工智能換臉工具輕松在任何視頻中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的代碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

功能強大的PHP集成開發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級代碼編輯軟件(SublimeText3)

熱門話題

Laravel 教程
1597
29
PHP教程
1488
72
實現(xiàn)Workerman文檔中的文件上傳與下載 實現(xiàn)Workerman文檔中的文件上傳與下載 Nov 08, 2023 pm 06:02 PM

實現(xiàn)Workerman文檔中的文件上傳與下載,需要具體代碼示例引言:Workerman是一款高性能的PHP異步網(wǎng)絡(luò)通訊框架,具備簡潔、高效、易用等特點。在實際開發(fā)中,文件上傳和下載是常見的功能需求,本文將介紹如何使用Workerman框架實現(xiàn)文件的上傳和下載,并給出具體的代碼示例。一、文件上傳:文件上傳是指將本地計算機上的文件傳輸至服務(wù)器端的操作。下面是使用

swoole和workerman哪個好 swoole和workerman哪個好 Apr 09, 2024 pm 07:00 PM

Swoole 和 Workerman 都是高性能 PHP 服務(wù)器框架。Swoole 以其異步處理、出色的性能和可擴展性而聞名,適用于需要處理大量并發(fā)請求和高吞吐量的項目。Workerman 提供了異步和同步模式的靈活性,具有直觀的 API,更適合易用性和處理較低并發(fā)量的項目。

如何實現(xiàn)Workerman文檔的基本使用方法 如何實現(xiàn)Workerman文檔的基本使用方法 Nov 08, 2023 am 11:46 AM

如何實現(xiàn)Workerman文檔的基本使用方法簡介:Workerman是一個高性能的PHP開發(fā)框架,它可以幫助開發(fā)者輕松構(gòu)建高并發(fā)的網(wǎng)絡(luò)應(yīng)用程序。本文將介紹Workerman的基本使用方法,包括安裝和配置、創(chuàng)建服務(wù)和監(jiān)聽端口、處理客戶端請求等。并給出相應(yīng)的代碼示例。一、安裝和配置Workerman在命令行中輸入以下命令來安裝Workerman:c

如何實現(xiàn)Workerman文檔中的定時器功能 如何實現(xiàn)Workerman文檔中的定時器功能 Nov 08, 2023 pm 05:06 PM

如何實現(xiàn)Workerman文檔中的定時器功能Workerman是一款強大的PHP異步網(wǎng)絡(luò)通信框架,它提供了豐富的功能,其中就包括定時器功能。使用定時器可以在指定的時間間隔內(nèi)執(zhí)行代碼,非常適合定時任務(wù)、輪詢等應(yīng)用場景。接下來,我將詳細介紹如何在Workerman中實現(xiàn)定時器功能,并提供具體的代碼示例。第一步:安裝Workerman首先,我們需要安裝Worker

如何實現(xiàn)Workerman文檔中的反向代理功能 如何實現(xiàn)Workerman文檔中的反向代理功能 Nov 08, 2023 pm 03:46 PM

如何實現(xiàn)Workerman文檔中的反向代理功能,需要具體代碼示例簡介:Workerman是一款高性能的PHP多進程網(wǎng)絡(luò)通信框架,提供了豐富的功能和強大的性能,廣泛應(yīng)用于Web實時通訊、長連接服務(wù)等場景。其中,Workerman還支持反向代理功能,可以實現(xiàn)服務(wù)器對外提供服務(wù)時的負載均衡和靜態(tài)資源緩存等功能。本篇文章將介紹如何使用Workerman實現(xiàn)反向代理功

Workerman開發(fā):如何實現(xiàn)基于UDP協(xié)議的實時視頻通話 Workerman開發(fā):如何實現(xiàn)基于UDP協(xié)議的實時視頻通話 Nov 08, 2023 am 08:03 AM

Workerman開發(fā):基于UDP協(xié)議的實時視頻通話摘要:本文將介紹如何使用Workerman框架實現(xiàn)基于UDP協(xié)議的實時視頻通話功能。我們將深入了解UDP協(xié)議的特點,并通過代碼示例展示如何搭建一個簡單但完整的實時視頻通話應(yīng)用。引言:在網(wǎng)絡(luò)通信中,實時視頻通話是一項非常重要的功能。傳統(tǒng)的TCP協(xié)議在實現(xiàn)實時性較高的視頻通話時,可能會有傳輸延遲等問題。而UDP

如何使用Workerman搭建高可用性負載均衡系統(tǒng) 如何使用Workerman搭建高可用性負載均衡系統(tǒng) Nov 07, 2023 pm 01:16 PM

如何使用Workerman搭建高可用性負載均衡系統(tǒng),需要具體代碼示例在現(xiàn)代技術(shù)領(lǐng)域中,隨著互聯(lián)網(wǎng)的快速發(fā)展,越來越多的網(wǎng)站和應(yīng)用程序需要處理大量的并發(fā)請求。為了實現(xiàn)高可用性和高性能,負載均衡系統(tǒng)成為了必不可少的組件之一。本文將介紹如何使用PHP開源框架Workerman搭建一個高可用性的負載均衡系統(tǒng),并提供具體的代碼示例。一、Workerman簡介Worke

實現(xiàn)Workerman文檔中的文件傳輸功能 實現(xiàn)Workerman文檔中的文件傳輸功能 Nov 08, 2023 pm 03:39 PM

Workerman是一款基于PHP開發(fā)的高性能異步事件驅(qū)動框架,它可以輕松實現(xiàn)TCP/UDP協(xié)議下的長連接開發(fā)。除此之外,Workerman還提供了實現(xiàn)文件傳輸?shù)墓δ埽梢杂糜诖笪募鬏?、?shù)據(jù)備份等場景。本文將介紹如何在Workerman中實現(xiàn)文件傳輸功能,并提供具體的代碼示例。一、文件上傳功能實現(xiàn)文件上傳功能需要客戶端將要上傳的文件發(fā)送給服務(wù)端,服務(wù)端驗證

See all articles