Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I simulate a non-responding server?

I have a web service which the customers use by inserting an external JavaScript (hosted on my servers). Recently, due to server outage - the external JavaScript became unavailable and my customers' websites came to a crawl as browser didn't load rest of the website until it loaded the JS (it goes into header of the websites).

I am trying to work out methods so that customers' website don't slow down even if my server goes down and for that I wanted to simulate a condition where the my server isn't responding. Note that if I specify a wrong URL, browser won't load the JS but in case URL is right and server isn't responding, browser will stall loading rest of the page. I want to simulate the last case. Any ideas how can I go about it?

PS: On server side, I am using the LAMP stack.

like image 407
Paras Chopra Avatar asked Feb 12 '10 14:02

Paras Chopra


2 Answers

Create a script that sleeps for a configurably long time

Something like

<?php
$how_long = $_GET['seconds'];
sleep($how_long);
echo "alert('Finished sleeping!');";
?>

Then you just access this script instead, for example by putting this in your HTML code <script src="http://example.com/hang_for.php?seconds=3600" />. That would sleep for an hour. There will be another timeouts that'll trigger first configured in php.ini, but that's exactly what you want to test, no?

like image 150
Vinko Vrsalovic Avatar answered Nov 04 '22 11:11

Vinko Vrsalovic


If the "P" in your LAMP is PHP, you could use the sleep function (documented here). Then, have your test page load your PHP script as the source of your Javascript to see what happens.

like image 2
Jacob Avatar answered Nov 04 '22 12:11

Jacob