How to Simulate Long HTTP Requests

Publikováno: 17.3.2020

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. Whenever I need to simulate a long HTTP request, I use a bit of PHP to […]

The post How to Simulate Long HTTP Requests appeared first on David Walsh Blog.

Celý článek

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.

Whenever I need to simulate a long HTTP request, I use a bit of PHP to make it happen:

&lgt;?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 -S localhost:8000

Now I can hit http://localhost:8000 and get the long request I want!

There are a number of ways you can accomplish these long form requests but this has always been a favorite of mine!

The post How to Simulate Long HTTP Requests appeared first on David Walsh Blog.

Nahoru
Tento web používá k poskytování služeb a analýze návštěvnosti soubory cookie. Používáním tohoto webu s tímto souhlasíte. Další informace