帶有PHP的HTML5 WebSockets(WAMP)



這是一個用PHP實現的簡單HTML5 WebSockets伺服器的演示。現在,伺服器僅連接一堆用戶,從每個用戶接收消息,然後向所有其他客戶端廣播相同的文本。

伺服器遵循草案76。我已經嘗試了幾篇有關設置自定義PHP伺服器的文章和教程,但是沒有什麼幫助。最有用的一個是在NetTuts上發布的一個,但即使這樣也只能將我帶到目前為止。

我目前的目標(因為這是我正在為網路課程進行的最終項目的一部分)是使用套接字編寫一個模擬股票交易的應用程序。幾個用戶將登錄並看到他們可以購買其股票的一些公司,然後所有信息都會實時更新。

我喜歡HTML5 WebSockets的地方是,絕對不需要AJAX。使用AJAX,為了使每個人都能立即保持同步,您必須多次調用伺服器。使用WebSocket,您在前端(客戶端)唯一要做的事情就是設置一個回調函數來處理來自伺服器的消息。而已!

一旦完成,我將在此以及最終項目中獲得詳細的教程。

有關此項目以及我正在進行或正在進行的其他項目的更多信息,請訪問我的產品組合,網址為http://www.rodrigo-silveira.com

9 comments
  1. how about some tutorials, examples, and step by step setups with more practical applications?  chat apps is always the first thing mentioned when talking about websockets.  not everyone wants chat apps.  how about an app where it's not just new info being inputted that displays right away on multiple clients… how about an app where data that is already saved on a database is displayed and that data can edited and re-edited by multiple people on multiple computers and the new data is shown to all clients in real-time.  sort of like the dead project called Google Wave, and their current application called Google Docs where there is multi-person collaboration on the documents and everyone sees the changes made by everyone else as soon as they happen.  how about some easy to follow video lessons on that?  reading manuals and documentation to learn things is not fun or quick.  it's faster when someone explains it and shows examples and maybe even provides downloads to quickly setup a working example on your own server.

  2. I have same problem it did not connect on localhost (WAMP) i also given server.php file path : localhost:8005/chat-app/server.php & i changed in php.ini enable sockets_dll then socket_bind is not defined error showing , please anybody help to resolve.

  3. how can I use the socket?

    I use wamp on windows, I was in command of the windows and typed:

    c: wamp bin php php5.3.5 php-q server.php

    and shows the error:

    Fatal error: Call to undefined function socket_create ()

  4. @casperbyc I've posted a more elaborate video of the WebSocket server in PHP titled 'HTML5 Websockets Tutorial & Demo'
    I'm working on a written tutorial right now, which I'm planning to follow up with a video tutorial. Stay tuned…

  5. can you explain how you set the server up or provide php server script? I tried many time but seems like all failed under php…. ><''

Comments are closed.