Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
en:comet:simple-php-chat-example [2017/05/18 04:20] levhav created |
en:comet:simple-php-chat-example [2019/12/18 02:05] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | + | <rst>EN::12-Examples::005-PHP chat example</rst> | |
- | An example of using the [[https://github.com/CppComet/comet-server|CppComet]] server to create a chat. For more information about CppComet, see [[en|documentation]] | + | <rst>Header: PHP chat example</rst> |
====== PHP chat example ====== | ====== PHP chat example ====== | ||
- | [[https://jsfiddle.net/Levhav/o35kvmn2/17/|jsfiddle.net online demo]] | + | An example of using the [[https://github.com/CppComet/comet-server|CppComet]] server to create a chat. |
+ | |||
+ | * [[https://jsfiddle.net/Levhav/o35kvmn2/17/|jsfiddle.net online demo]] | ||
+ | * [[https://github.com/CppComet/php-chat-example|Github repo]] | ||
{{ :en:comet:chat.gif |chat demo}} | {{ :en:comet:chat.gif |chat demo}} | ||
- | ===== Scheme of chat ===== | + | ====== Scheme of chat ====== |
Typical scheme of chat: | Typical scheme of chat: | ||
Line 20: | Line 23: | ||
* Add message to database (optional) | * Add message to database (optional) | ||
- | ==== Step 1. Connecting to the comet server ==== | + | ====== Step 1. Connecting to the comet server ====== |
[[https://github.com/CppComet/comet-server|CppComet]] has cloud saas alternative that can be used for testing and demo access. In the following examples I will use demonstration access from https://comet-server.com for those who could not or were too lazy to [[https://github.com/CppComet/comet-server#building-from-source|deploy the server on their VPS]] | [[https://github.com/CppComet/comet-server|CppComet]] has cloud saas alternative that can be used for testing and demo access. In the following examples I will use demonstration access from https://comet-server.com for those who could not or were too lazy to [[https://github.com/CppComet/comet-server#building-from-source|deploy the server on their VPS]] | ||
Line 38: | Line 41: | ||
- | ==== Step 2. send message to server ==== | + | ====== Step 2. Send message to server ====== |
* Send ajax query to php back-end | * Send ajax query to php back-end | ||
Line 61: | Line 64: | ||
- | ==== Step 3. receive message from comet server ==== | + | ====== Step 3. Receive message from comet server ====== |
- | subscription Code to the pipe on comet server. This callback will be called when somebody send message into channel `simplechat` | + | Subscription code to the pipe on comet server. This callback will be called when somebody sends message into channel `simplechat` |
<code JavaScript> | <code JavaScript> | ||
Line 73: | Line 76: | ||
</code> | </code> | ||
- | ==== Links ==== | + | ====== Full chat code ====== |
+ | |||
+ | <html> | ||
+ | <script async src="//jsfiddle.net/Levhav/o35kvmn2/17/embed/"></script> | ||
+ | </html> | ||
+ | |||
+ | ====== Links ====== | ||
* [[en:comet:javascript_api|JavaScript API]] | * [[en:comet:javascript_api|JavaScript API]] | ||
Line 79: | Line 88: | ||
* [[https://jsfiddle.net/o35kvmn2/5/|Online demo]] | * [[https://jsfiddle.net/o35kvmn2/5/|Online demo]] | ||
* [[https://github.com/CppComet/comet-server|CppComet]] | * [[https://github.com/CppComet/comet-server|CppComet]] | ||
+ | * [[https://www.codeproject.com/script/Articles/ArticleVersion.aspx?waid=235463&aid=1181698|Creating a simple chat using CppComet]] | ||