- 授权协议: MIT
- 开发语言: PHP
- 操作系统: 跨平台
- 软件首页: https://gitee.com/hhxsv5/php-sse
- 软件文档: https://gitee.com/hhxsv5/php-sse/blob/master/README.md
软件介绍
PHP SSE: Server-sent Events,一个简单有效的库,通过 PHP 实现了 HTML5 的服务器发送事件,用于实时从服务器推送事件到客户端,比 Websocket 更容易。
要求:PHP 5.4 or later
示例代码
Javascript demo
Client: receiving events from the server
//withCredentials=true: pass the cross-domain cookies to server-side
var source = new EventSource("http://127.0.0.1:9001/push.php", {withCredentials:true});
source.addEventListener("new-msgs", function(event){
console.log(event.data);//get data
}, false);PHP demo
Server: sending events from the server by pure php
include './vendor/autoload.php';
use Hhxsv5\SSE\SSE;
use Hhxsv5\SSE\Update;
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
header('Connection: keep-alive');
header('X-Accel-Buffering: no');//Nginx: unbuffered responses suitable for Comet and HTTP streaming applications
(new SSE())->start(new Update(function () {
$id = mt_rand(1, 1000);
$newMsgs = [
[
'id' => $id,
'title' => 'title' . $id,
'content' => 'content' . $id,
],
];//get data from database or servcie.
if (!empty($newMsgs)) {
return json_encode(['newMsgs' => $newMsgs]);
}
return false;//return false if no new messages
}), 'new-msgs');
C++ Primer Plus
Stephen Prata / 张海龙、袁国忠 / 人民邮电出版社 / 2012-6-19 / 99.00元
C++是在C语言基础上开发的一种集面向对象编程、通用编程和传统的过程化编程于一体的编程语言,是C语言的超集。本书是根据2003年的ISO/ANSI C++标准编写的。通过大量短小精悍的程序详细而全面地阐述了C++的基本概念和技术。全书分为18章和10个附录,分别介绍了C++程序的运行方式、基本数据类型、复合数据类型、循环和关系表达式、分支语句和逻辑操作符、函数重载和函数模板、内存模型和名称空间、类......一起来看看 《C++ Primer Plus》 这本书的介绍吧!
