安裝 Gateway過程1、下載gateway zip包linux版,http://www.workerman.net/download 2、使用Mac自帶的php無效,報Please install pcntl extension. See http://doc3.workerman.net/appendices/install-extension.html,沒有去深究怎么安裝擴展,而是改用了xmapp的可以
3、嘗試使用小程序連接,小程序沒有執行沒有報錯
4、Error during WebSocket handshake: Invalid status line
通過改動start_gateway.php第21行 $gateway = new Gateway("websocket://0.0.0.0:8282"); 于是就成功了
5、通過onSocketMessage接收服務端發來的消息
小程序代碼:onLoad: function () { wx.connectSocket({ url: 'ws://127.0.0.1:8282', success: function (res) { console.log('連接成功') }, fail: function (res) { console.log('連接失敗') } }) wx.onSocketOpen(function(res) { console.log('WebSocket連接已打開!') wx.sendSocketMessage({ data: "huangxj" }) }) wx.onSocketError(function(res){ console.log('WebSocket連接打開失敗,請檢查!') }) wx.onSocketMessage(function(res) { console.log('收到服務器內容:' + res.data) }) } 順便記錄2條關于php的命令
php --ini 查看php.ini所在目錄 |