http 模拟请求
It happens less frequently these days but there are times when we need to accommodate for a HTTP request timing out. The service could be down, under heavy traffic, or just poorly coded, or any host of other issues.
如今,这种情况的发生频率降低了,但是有时候我们需要适应HTTP请求超时。 服务可能会关闭,通信繁忙或只是编码不正确,或其他许多问题。
Whenever I need to simulate a long HTTP request, I use a bit of PHP to make it happen:
每当我需要模拟长HTTP请求时,我都会使用一些PHP来实现它:
<?php
// Don't resolve this request for 5 seconds
sleep(5);
// A generic response
echo 'This is the response!';
// ... or hit a URL to make the case more realistic
echo file_get_contents('https://website.tld/endpoint');
?>
With that script created, I make PHP start a server so I can make the request locally:
创建该脚本后,我使PHP启动服务器,以便可以在本地发出请求:
php -S localhost:8000
Now I can hit http://localhost:8000
and get the long request I want!
现在,我可以访问http://localhost:8000
并得到我想要的长请求!
There are a number of ways you can accomplish these long form requests but this has always been a favorite of mine!
您可以通过多种方式来完成这些长格式请求,但这一直是我的最爱!
翻译自: https://davidwalsh.name/how-to-simulate-long-http-requests
http 模拟请求