Using the least resources possible, what would be the best way to simulate a hung web application?

不想你离开。 提交于 2019-12-25 02:29:32

问题


I want to create a page that simulates a hung/frozen web page. For example, I could use a really long "sleep" in PHP. But if I wanted to make this a public tool, I could well imagine this might eat up server resource (sockets, memory, etc - I'm not that experienced at this level of abstraction) and eventually cause real problems for the server.

I don't want to simply close the socket with the client, because that would not provide the type of "waiting" behavior I want to simulate.

The solution doesn't have to be PHP related. That was just an example. It can be any language and/or web server. The only criteria is FOSS on Linux.


回答1:


You can simply use netcat to listen on a port and return nothing.

nc -l localhost 8080

Or if you wanted it to continue listening when the client has closed the connection

while (TRUE); do nc -l localhost 8080; done

edit: some versions of nc have the -k option to force netcat to continue listening after the socket is closed. In those cases you don't need to loop.



来源:https://stackoverflow.com/questions/24132551/using-the-least-resources-possible-what-would-be-the-best-way-to-simulate-a-hun

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!