- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
首先我会说这在我的本地机器上完美运行,下面的 js 示例连接到 stream.php 并每秒接收服务器当前时间的持续更新。
var source = new EventSource("stream.php");
source.addEventListener('message', function(e) {
console.log(e);
}, false);
source.addEventListener('open', function(e) {
console.log(e);
}, false);
source.addEventListener('error', function(e) {
if (e.readyState == EventSource.CLOSED) {
console.log('closed');
}
}, false);
while(true)
{
// Headers must be processed line by line.
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
// Set data line
print "data: " . date( 'G:H:s', time() ) . PHP_EOL . PHP_EOL;
// Toilet
flush();
// Wait one second.
sleep(1);
}
我确实预料到上传到现场开发人员后会有一点延迟。服务器。但是会有大约 15 到 20 分钟的时间延迟。在我看到第一个条目之前。
连接不会断开。 (可能已经进行了 40 分钟以上。)这只是一个 Apache 循环问题(意味着是时候查看网络套接字了)还是我可以做些什么来解决这个问题?
最佳答案
Server.php需要如下:
while(true)
{
// Headers must be processed line by line.
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
// Set data line
print "Event: server-time" . PHP_EOL;
print "data: " . date( 'G:H:s', time() ) . PHP_EOL;
print PHP_EOL;
ob_end_flush(); // Strange behaviour, will not work
flush(); // Unless both are called !
// Wait one second.
sleep(1);
}
关于php - 服务器发送的事件有效,但时间延迟很大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12297740/
有没有一个简单的答案:为什么 GHC 这么大? OCaml:2MB Python:15MB SBCL:9MB OpenJRE - 26MB GHC:113MB 对“如果 Haskell 是正确的工具,
我发现我的 access_log 占用了我的大部分硬盘。它的大小超过 200 GB。我怎样才能重置它? 我在装有 Plesk 的 CentOS 服务器上使用 Apache 2.2.3。 谢谢你们 !
我正在使用 Java 中的 BeanShell 解释器来解决字符串计算问题。问题是我自己做了一些解释器无法完成的解析并将部分结果存储在 BigInteger 中。然后我将所有内容拼凑起来并交给解释器来
我在我的 android 项目中使用 OpenCV native 库。它是一个带有一个 CameraScreen 的 hello world 项目,它已经有 40mb。我怎样才能减少 apk 的大小,
我使用基于 Laravel 和 Vue.js 的 Laravue Dashboard,在在线服务器上运行,而不是本地主机,它是全新安装,没有进行任何编辑。 我的问题是: 运行 npm run watc
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 5 年前。 Improve this qu
我广泛使用了 Kendo DataSourceResult ToDataSourceResult(this IQueryable enumerable, DataSourceRequest reque
我使用 phonegap 构建 html\css 应用程序陪审团手机给我 div: 并且模拟器中的最小高度太大,我在底部看到黑线像这样: 如果我在 css 文件中更改 min-height: 736
以下工作正常但速度太慢。只需要知道B表中有匹配的记录,有什么技巧吗? (奇怪的是相反的搜索:找到不加入的记录(IS NULL)非常快) SELECT TableA.id FROM TableA
我正在使用 Vue.js,我的项目中只有 4 个组件。 我只导入了bootstrap、jquery 和lodash: import { map } from 'lodash'; import 'boo
我有 2 个字谜检测功能;一个使用排序和比较,另一个跟踪每个字母字符出现的次数。 这里假设传递给函数的两个字符串是相同的,第一个随机生成(未排序),第二个 = 给第一个,这样两个函数都“一路”执行并返
我正在尝试编写一个脚本,该脚本将通过 HTTP 同时下载最多 N 个文件。 我以前用过 AnyEvent::Worker::Pool管理阻塞任务池。我也用过 AnyEvent::HTTP结合AnyEv
我是一名优秀的程序员,十分优秀!