Skip to content

Commit 6610c60

Browse files
increase timeout for verifying endpoint and write received http response to php error log
1 parent 51152a1 commit 6610c60

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/class-endpoint-installer.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ public static function verify()
6969
private static function verify_internal()
7070
{
7171
$tracker_url = site_url('/koko-analytics-collect.php?nv=1&p=0&up=1&test=1');
72-
$response = wp_remote_get($tracker_url);
72+
$response = wp_remote_get($tracker_url, [
73+
'timeout' => 10,
74+
]);
7375
if (is_wp_error($response)) {
7476
return __('Error requesting endpoint: ', 'koko-analytics') . join(', ', $response->get_error_messages());
7577
}
@@ -78,15 +80,16 @@ private static function verify_internal()
7880
$headers = wp_remote_retrieve_headers($response);
7981

8082
// verify whether we get an expected response
81-
if (
82-
$status == 200
83+
if ($status == 200
8384
&& isset($headers['Content-Type'])
8485
&& str_contains($headers['Content-Type'], 'text/plain')
8586
) {
8687
return true;
8788
}
8889

89-
return __('Endpoint did not return the expected response', 'koko-analytics');
90+
error_log(sprintf("Koko Analaytics: Error verifying optimized endpoint because it did not return the expected HTTP response.\nHTTP code: %s\nHTTP headers: %s\nHTTP body: %s", $status, var_export($headers, true), wp_remote_retrieve_body($response)));
91+
92+
return __('Endpoint did not return the expected response.', 'koko-analytics');
9093
}
9194

9295
/**

0 commit comments

Comments
 (0)