Skip to content

Commit d4c2e33

Browse files
committed
Use common failed() function to print timing info and exit
1 parent 6b5d953 commit d4c2e33

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

scripts/start-servers.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ function make_ctx($preset, $method = "POST") {
4747
return $ctx;
4848
}
4949

50+
function failed()
51+
{
52+
printf("\nLast operation took: %.2f secs\n", lap());
53+
exit(1);
54+
}
55+
5056
function mo_http_request($uri, $context) {
5157
global $http_response_header;
5258

@@ -55,21 +61,20 @@ function mo_http_request($uri, $context) {
5561
if ($result === false) {
5662
printf("HTTP request to %s failed:\n", $uri);
5763
var_dump($http_response_header);
58-
printf("Last operation took: %.2f secs\n", lap());
59-
exit(1);
64+
failed();
6065
}
6166

6267
return $result;
6368
}
6469

65-
function json_decode_or_fail(/* json_decode() args */)
70+
function json_decode_or_fail(...$args)
6671
{
67-
$decoded = call_user_func_array('json_decode', func_get_args());
72+
$decoded = json_decode(...$args);
6873

6974
if ($decoded === NULL && json_last_error() !== JSON_ERROR_NONE) {
7075
printf("\njson_decode() failed: %s\n", json_last_error_msg());
7176
var_dump(func_get_arg(0));
72-
exit(1);
77+
failed();
7378
}
7479

7580
return $decoded;
@@ -106,7 +111,7 @@ function json_decode_or_fail(/* json_decode() args */)
106111

107112
if (!isset($decode["id"])) {
108113
printf("\"id\" field not found in server response:\n%s\n", $decode);
109-
exit(1);
114+
failed();
110115
}
111116

112117
$SERVERS[$decode["id"]] = isset($decode["mongodb_auth_uri"]) ? $decode["mongodb_auth_uri"] : $decode["mongodb_uri"];
@@ -124,7 +129,7 @@ function json_decode_or_fail(/* json_decode() args */)
124129

125130
if (!isset($decode["id"])) {
126131
printf("\"id\" field not found in replica set response:\n%s\n", $decode);
127-
exit(1);
132+
failed();
128133
}
129134

130135
$SERVERS[$decode["id"]] = isset($decode["mongodb_auth_uri"]) ? $decode["mongodb_auth_uri"] : $decode["mongodb_uri"];

0 commit comments

Comments
 (0)