PHP刷新问题
好的,我有这个 PHP 脚本,它在一个漂亮的小无限循环中运行(有睡眠,不用担心)。我将它用作可以从任何计算机访问的页面来监视我的数据库统计信息。每 2 秒,它从数据库获取统计数据并将其显示在屏幕上。
现在,这在我的 Windows 机器上的 XAMPP 上运行得很好。我试图让它在我的 linux 网络服务器上工作,使用 PHP 5.3.5 运行 apache2,但由于某种原因它实际上不会显示任何内容(它不会进入空白页面,它只是停留在页面上我在进入监视器页面之前,但“工作”轮在旋转)。我觉得这是某种缓存的东西,它不想显示页面,直到它完成运行脚本(尽管我需要它)。我每2秒使用一次flush()和ob_flush(),并确保我的php.ini文件中的output_buffering = off和zlib.output_compression = off。
我意识到这个问题似乎被问了很多次,但我已经尝试了有关该主题的所有方法,但最终失败了。
注意:就像我说的,这在我使用 apache 和 PHP 5.3.6 安装的 XAMPP 上运行得很好。我的问题不是如何找到替代品,而是更多关于为什么它可以在那里工作,但不能在我的 Linux 网络服务器上工作。
Ok, so I have this PHP script that runs in a nice little infinite loop (with sleeps, don't worry). I use it as a page I can go to from any computer to monitor my database statistics. Every 2 seconds, it gets stats from the DB and displays them on the screen.
Now, this works just fine on XAMPP on my Windows machine. I'm trying to get it to work on my linux webserver, running apache2 with PHP 5.3.5, but for some reason it won't actually display anything (it doesn't go to a blank page, it just stays at the page I was at before going to the monitor page, but with the "working" wheel spinning). I feel like this is some sort of caching thing, it doesn't want to display the page until it's finished running the script (although I NEED it to). I use flush() and ob_flush() after every 2 seconds, and I made sure that output_buffering = off and zlib.output_compression = off in my php.ini file.
I realize this question seems to have been asked a lot, but I've tried everything I can find on the subject with ultimate failure.
NOTE: like I said, this works FINE on my XAMPP install with apache and PHP 5.3.6. My question isn't so much about how to find alternatives, but more with regards to WHY it works there but not on my linux webserver.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
让 php 脚本运行“无限”时间几乎是不合适的。您可以:
)
所有这些解决问题的方法都会避免您现在遇到的那种头痛。
Having php script run for an "infinite" amount of time is almost never appropriate. You can:
<meta http-equiv="refresh" content="5">
)All of these ways of approaching the problem would save you the type of headaches you're experiencing now.
您可以执行以下操作:
让您的脚本将参数写入 javascript,以便您可以每 2 秒使用新参数重新加载页面。示例:
因此,如果您需要对每个 sql 查询执行 Db 偏移量,则可以在 url 中传递该参数。有一个无限循环似乎是一个好主意,但也许你应该重新评估你的代码,看看你是否真的需要它,或者你是否可以通过这种方式实现它
Here is what you can do,
Have your script write the parameters to the javascript, so you can reload your page every 2 seconds with new parameters. example:
so if you need to do a Db offset on each sql query, you can pass that parameter in the url. Having an infinite loop might seem like a good idea, but maybe you should reevalute your code and see if you really need it, or if you can implement it this way