Skip to content

Instantly share code, notes, and snippets.

@bertrand-lupart
Created January 3, 2018 17:16
Show Gist options
  • Save bertrand-lupart/c06d793858d10bc8ea203773ffc5a637 to your computer and use it in GitHub Desktop.
Save bertrand-lupart/c06d793858d10bc8ea203773ffc5a637 to your computer and use it in GitHub Desktop.
Indefinitely test an URL, displaying HTTP return code and delay in nanoseconds
#!/usr/bin/env pike
int timeout_data=10;
int timeout=40;
string host_check = "www.example.com";
string query_check = "GET / HTTP/1.1";
int port_check = 80;
mapping headers = ([ "User-Agent":"Pike Loop HTTP test" ]);
Protocols.HTTP.Query http=Protocols.HTTP.Query();
// time counters
int start = 0;
int stop = 0;
int main(int argc, array(string) argv)
{
launch();
return -1;
}
void launch()
{
start=0; stop=0;
http->set_callbacks(http_ok, http_ko);
http->data_timeout = timeout_data;
http->timeout = timeout;
start=gethrtime(1);
http->async_request(host_check, port_check, query_check, headers);
}
void http_ok()
{
stop = gethrtime(1);
write("-- HTTP %O (%d ns)\n", http.status, (stop-start));
launch();
}
void http_ko()
{
stop = gethrtime(1);
werror("!! timeout (%d ns)\n", (stop-start));
launch();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment