[英]Is there any way to get and show status of a running server process at a web page?
What I have is a process on the server that runs and takes a lot of time. 我所拥有的是服务器上运行的过程,该过程花费大量时间。 It essentially builds some data tables that are displayed on a page on post-back.
它实质上是构建一些数据表,这些数据表在回发时显示在页面上。
What I want is a way to log progress somewhere while the server process is running and report that on the page I am looking at before it is refreshed with the completed data. 我想要的是一种在服务器进程运行时在某处记录进度并在刷新完成的数据之前在我正在查看的页面上报告该进度的方法。
Is this even possible? 这有可能吗? The best way I can think of to do this is to log progress to a file on the server and periodically read the file contents via Ajax/Javascript, but this seems like a kludge.
我能想到的最好的方法是将进度记录到服务器上的文件中,并通过Ajax / Javascript定期读取文件内容,但这似乎有点麻烦。
Maybe this is possible using multiple pages or threads. 也许可以使用多个页面或线程。 I'm not sure.
我不确定。
Any suggestions? 有什么建议么?
Edit:
编辑:
The main goal is to show a progress bar of some sort on the web page to show the above mentioned progress. 主要目的是在网页上显示某种进度条,以显示上述进度。
Is this even possible?
这有可能吗?
Yes, but it's not easy, or pretty. 是的,但这并不容易,也不是很漂亮。
The best way I can think of to do this is to log progress to a file on the server and periodically read the file contents via Ajax/Javascript, but this seems like a kludge.
我能想到的最好的方法是将进度记录到服务器上的文件中,并通过Ajax / Javascript定期读取文件内容,但这似乎有点麻烦。
Yep, pretty much. 是的,差不多。 Other options are to use a database to store the info, or session, but any storage location that can be accessed somehow through an Ajax request would work.
其他选项是使用数据库存储信息或会话,但是可以通过Ajax请求以某种方式访问的任何存储位置都可以使用。 You'll no doubt want to make a web service or similar to abstract away whatever storage method you use.
毫无疑问,您想制作一个Web服务或类似服务以抽象化您使用的任何存储方法。
Here is an implementation of that general approach in a Microsoft example. 这是Microsoft示例中该常规方法的实现。 It uses Session to store the current progress, and relied heavily on ASP-based constructs.
它使用Session存储当前的进度,并严重依赖基于ASP的构造。
Another avenue entirely would be to set up a websocket between the client and the server which would allow you to push information from the server to the client. 完全可以采用的另一种方法是在客户端和服务器之间建立一个Websocket,这将允许您将信息从服务器推送到客户端。 It would likely perform better (reduced network IO), although it may not be easier to set up.
尽管设置起来可能并不容易,但它可能会表现更好(减少了网络IO)。 I don't have any examples (or experience attempting) such a solution though.
我没有任何示例(或尝试尝试)这样的解决方案。
ajax,ajax,xhr,jsonp以及进程中的里程碑,以便您可以指定状态
If the process you are running is independent of your page (for example, a shell script inside a server), you can write the intermediate result of this script in a text file accessible by javascript (for example in http://contosoweb.com/web/log.txt ), and update it periodically from the page using a timer and some jquery. 如果您正在运行的进程独立于您的页面(例如,服务器内部的Shell脚本),则可以将此脚本的中间结果写入可通过javascript访问的文本文件中(例如,在http://contosoweb.com中) /web/log.txt ),并使用计时器和一些jquery从页面定期对其进行更新。
Here you have the info of .Ajax in the jQuery Docs: http://api.jquery.com/jQuery.ajax/ 在jQuery Docs中,您具有.Ajax的信息: http ://api.jquery.com/jQuery.ajax/
And here how to use a timer: How to set a timer in javascript 还有如何使用计时器: 如何在javascript中设置计时器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.