NitroPack - Version 1.4.1

Version Description

  • Improvement: Performance improvements in content updates
  • Improvement: Better compatibility with Download Monitor
Download this release

Release Info

Developer nitropack
Plugin Icon 128x128 NitroPack
Version 1.4.1
Comparing to
See all releases

Code changes from version 1.4.0 to 1.4.1

constants.php CHANGED
@@ -6,7 +6,7 @@ function nitropack_trailingslashit($string) {
6
  return rtrim( $string, '/\\' ) . '/';
7
  }
8
 
9
- define( 'NITROPACK_VERSION', '1.4.0' );
10
  define( 'NITROPACK_OPTION_GROUP', 'nitropack' );
11
  define( 'NITROPACK_DATA_DIR', nitropack_trailingslashit(WP_CONTENT_DIR) . 'nitropack' );
12
  define( 'NITROPACK_CONFIG_FILE', nitropack_trailingslashit(NITROPACK_DATA_DIR) . 'config.json' );
6
  return rtrim( $string, '/\\' ) . '/';
7
  }
8
 
9
+ define( 'NITROPACK_VERSION', '1.4.1' );
10
  define( 'NITROPACK_OPTION_GROUP', 'nitropack' );
11
  define( 'NITROPACK_DATA_DIR', nitropack_trailingslashit(WP_CONTENT_DIR) . 'nitropack' );
12
  define( 'NITROPACK_CONFIG_FILE', nitropack_trailingslashit(NITROPACK_DATA_DIR) . 'config.json' );
functions.php CHANGED
@@ -167,7 +167,8 @@ function is_valid_nitropack_beacon() {
167
  if (function_exists("hash_hmac") && function_exists("hash_equals")) {
168
  $url = base64_decode($_POST["nitroBeaconUrl"]);
169
  $cookiesJson = !empty($_POST["nitroBeaconCookies"]) ? base64_decode($_POST["nitroBeaconCookies"]) : ""; // We need to fall back to empty string to remain backwards compatible. Otherwise cache files invalidated before an upgrade will never get updated :(
170
- $localHash = hash_hmac("sha512", $url.$cookiesJson, $siteConfig["siteSecret"]);
 
171
  return hash_equals($_POST["nitroBeaconHash"], $localHash);
172
  } else {
173
  return !empty($_POST["nitroBeaconUrl"]);
@@ -188,11 +189,12 @@ function nitropack_handle_beacon() {
188
  try {
189
  $hasLocalCache = $nitro->hasLocalCache(false);
190
  $proxyPurgeOnly = !empty($_POST["proxyPurgeOnly"]);
 
191
 
192
  if (!$proxyPurgeOnly) {
193
  if (!$hasLocalCache) {
194
  header("X-Nitro-Beacon: FORWARD");
195
- $hasCache = $nitro->hasRemoteCache("default", false); // Download the new cache file
196
  printf("Cache %s", $hasCache ? "fetched" : "requested");
197
  } else {
198
  header("X-Nitro-Beacon: SKIP");
@@ -566,9 +568,10 @@ function nitropack_get_beacon_script() {
566
  if (null !== $nitro = get_nitropack_sdk($siteConfig["siteId"], $siteConfig["siteSecret"]) ) {
567
  $url = $nitro->getUrl();
568
  $cookiesJson = json_encode($nitro->supportedCookiesFilter(NitroPack\SDK\NitroPack::getCookies()));
 
569
 
570
  if (function_exists("hash_hmac") && function_exists("hash_equals")) {
571
- $hash = hash_hmac("sha512", $url.$cookiesJson, $siteConfig["siteSecret"]);
572
  } else {
573
  $hash = "";
574
  }
@@ -581,9 +584,9 @@ function nitropack_get_beacon_script() {
581
  if (!window.NITROPACK_STATE || window.NITROPACK_STATE != 'FRESH') {
582
  var proxyPurgeOnly = " . ($proxyPurgeOnly ? 1 : 0) . ";
583
  if (typeof navigator.sendBeacon !== 'undefined') {
584
- var nitroData = new FormData(); nitroData.append('nitroBeaconUrl', '$url'); nitroData.append('nitroBeaconCookies', '$cookiesb64'); nitroData.append('nitroBeaconHash', '$hash'); nitroData.append('proxyPurgeOnly', '$proxyPurgeOnly'); navigator.sendBeacon(location.href, nitroData);
585
  } else {
586
- var xhr = new XMLHttpRequest(); xhr.open('POST', location.href, true); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.send('nitroBeaconUrl={$url}&nitroBeaconCookies={$cookiesb64}&nitroBeaconHash={$hash}&proxyPurgeOnly={$proxyPurgeOnly}');
587
  }
588
  }
589
  </script>";
@@ -1097,6 +1100,12 @@ function nitropack_purge($url = NULL, $tag = NULL, $reason = NULL) {
1097
 
1098
  function nitropack_log_purge($url = NULL, $tag = NULL, $reason = NULL) {
1099
  global $np_loggedPurges;
 
 
 
 
 
 
1100
 
1101
  $keyBase = "";
1102
  if ($url) {
@@ -1104,25 +1113,22 @@ function nitropack_log_purge($url = NULL, $tag = NULL, $reason = NULL) {
1104
  }
1105
 
1106
  if ($tag) {
1107
- if (is_array($tag)) {
1108
- $tag = array_map('nitropack_filter_tag', $tag);
1109
- $keyBase .= implode(",", $tag);
1110
- } else {
1111
- $tag = nitropack_filter_tag($tag);
1112
- $keyBase .= $tag;
1113
- }
1114
- }
1115
-
1116
- if ($reason) {
1117
- $keyBase .= $reason;
1118
  }
1119
 
1120
  $purgeRequestKey = md5($keyBase);
1121
- $np_loggedPurges[$purgeRequestKey] = array(
1122
- "url" => $url,
1123
- "tag" => $tag,
1124
- "reason" => $reason
1125
- );
 
 
 
 
 
 
1126
  }
1127
 
1128
  function nitropack_invalidate($url = NULL, $tag = NULL, $reason = NULL) {
@@ -1141,6 +1147,11 @@ function nitropack_invalidate($url = NULL, $tag = NULL, $reason = NULL) {
1141
 
1142
  function nitropack_log_invalidate($url = NULL, $tag = NULL, $reason = NULL) {
1143
  global $np_loggedInvalidations;
 
 
 
 
 
1144
 
1145
  $keyBase = "";
1146
  if ($url) {
@@ -1148,30 +1159,35 @@ function nitropack_log_invalidate($url = NULL, $tag = NULL, $reason = NULL) {
1148
  }
1149
 
1150
  if ($tag) {
1151
- if (is_array($tag)) {
1152
- $tag = array_map('nitropack_filter_tag', $tag);
1153
- $keyBase .= implode(",", $tag);
1154
- } else {
1155
- $tag = nitropack_filter_tag($tag);
1156
- $keyBase .= $tag;
1157
- }
1158
  }
1159
 
1160
- if ($reason) {
1161
- $keyBase .= $reason;
 
 
 
 
 
 
 
 
 
1162
  }
 
1163
 
1164
- $invalidateRequestKey = md5($keyBase);
1165
- $np_loggedInvalidations[$invalidateRequestKey] = array(
1166
- "url" => $url,
1167
- "tag" => $tag,
1168
- "reason" => $reason
1169
- );
1170
  }
1171
 
1172
  function nitropack_execute_purges() {
1173
  global $np_loggedPurges;
1174
  if (!empty($np_loggedPurges)) {
 
1175
  foreach ($np_loggedPurges as $requestKey => $data) {
1176
  nitropack_sdk_purge($data["url"], $data["tag"], $data["reason"]);
1177
  }
@@ -1181,6 +1197,7 @@ function nitropack_execute_purges() {
1181
  function nitropack_execute_invalidations() {
1182
  global $np_loggedInvalidations;
1183
  if (!empty($np_loggedInvalidations)) {
 
1184
  foreach ($np_loggedInvalidations as $requestKey => $data) {
1185
  nitropack_sdk_invalidate($data["url"], $data["tag"], $data["reason"]);
1186
  }
@@ -1605,6 +1622,14 @@ function nitropack_extend_nonce_life($life) {
1605
  // - a request may seem cachable at first, but be determined uncachable during runtime (example: visit to a URL of a page whose post type does not match the enabled cacheable post types, or a cart, checkout page, etc.)
1606
 
1607
  if ((null !== $nitro = get_nitropack_sdk())) {
 
 
 
 
 
 
 
 
1608
  $cacheExpiration = $nitro->getConfig()->PageCache->ExpireTime;
1609
  return $cacheExpiration > $life ? $cacheExpiration : $life; // Extend the life of cacheable nonces up to the cache expiration time if needed
1610
  }
@@ -2018,6 +2043,9 @@ function nitropack_update_current_blog_config($siteId, $siteSecret, $blogId, $en
2018
  "alwaysBuffer" => $alwaysBuffer,
2019
  "isEzoicActive" => nitropack_is_ezoic_active(),
2020
  "isNginxHelperActive" => nitropack_is_nginx_helper_active(),
 
 
 
2021
  "pluginVersion" => NITROPACK_VERSION
2022
  );
2023
  return nitropack_set_config($staticConfig);
@@ -2438,7 +2466,8 @@ function nitropack_plugin_notices() {
2438
  } else {
2439
  if (
2440
  (!array_key_exists("isEzoicActive", $siteConfig) || $siteConfig["isEzoicActive"] !== nitropack_is_ezoic_active()) ||
2441
- (!array_key_exists("isNginxHelperActive", $siteConfig) || $siteConfig["isNginxHelperActive"] !== nitropack_is_nginx_helper_active())
 
2442
  ) {
2443
  if (!nitropack_update_current_blog_config($siteId, $siteSecret, $blogId)) {
2444
  $errors[] = "The NitroPack static config file cannot be updated. Please make sure that the /wp-content/nitropack/ directory is writable and refresh this page.";
167
  if (function_exists("hash_hmac") && function_exists("hash_equals")) {
168
  $url = base64_decode($_POST["nitroBeaconUrl"]);
169
  $cookiesJson = !empty($_POST["nitroBeaconCookies"]) ? base64_decode($_POST["nitroBeaconCookies"]) : ""; // We need to fall back to empty string to remain backwards compatible. Otherwise cache files invalidated before an upgrade will never get updated :(
170
+ $layout = !empty($_POST["layout"]) ? $_POST["layout"] : "";
171
+ $localHash = hash_hmac("sha512", $url.$cookiesJson.$layout, $siteConfig["siteSecret"]);
172
  return hash_equals($_POST["nitroBeaconHash"], $localHash);
173
  } else {
174
  return !empty($_POST["nitroBeaconUrl"]);
189
  try {
190
  $hasLocalCache = $nitro->hasLocalCache(false);
191
  $proxyPurgeOnly = !empty($_POST["proxyPurgeOnly"]);
192
+ $layout = !empty($_POST["layout"]) ? $_POST["layout"] : "default";
193
 
194
  if (!$proxyPurgeOnly) {
195
  if (!$hasLocalCache) {
196
  header("X-Nitro-Beacon: FORWARD");
197
+ $hasCache = $nitro->hasRemoteCache($layout, false); // Download the new cache file
198
  printf("Cache %s", $hasCache ? "fetched" : "requested");
199
  } else {
200
  header("X-Nitro-Beacon: SKIP");
568
  if (null !== $nitro = get_nitropack_sdk($siteConfig["siteId"], $siteConfig["siteSecret"]) ) {
569
  $url = $nitro->getUrl();
570
  $cookiesJson = json_encode($nitro->supportedCookiesFilter(NitroPack\SDK\NitroPack::getCookies()));
571
+ $layout = nitropack_get_layout();
572
 
573
  if (function_exists("hash_hmac") && function_exists("hash_equals")) {
574
+ $hash = hash_hmac("sha512", $url.$cookiesJson.$layout, $siteConfig["siteSecret"]);
575
  } else {
576
  $hash = "";
577
  }
584
  if (!window.NITROPACK_STATE || window.NITROPACK_STATE != 'FRESH') {
585
  var proxyPurgeOnly = " . ($proxyPurgeOnly ? 1 : 0) . ";
586
  if (typeof navigator.sendBeacon !== 'undefined') {
587
+ var nitroData = new FormData(); nitroData.append('nitroBeaconUrl', '$url'); nitroData.append('nitroBeaconCookies', '$cookiesb64'); nitroData.append('nitroBeaconHash', '$hash'); nitroData.append('proxyPurgeOnly', '$proxyPurgeOnly'); nitroData.append('layout', '$layout'); navigator.sendBeacon(location.href, nitroData);
588
  } else {
589
+ var xhr = new XMLHttpRequest(); xhr.open('POST', location.href, true); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.send('nitroBeaconUrl={$url}&nitroBeaconCookies={$cookiesb64}&nitroBeaconHash={$hash}&proxyPurgeOnly={$proxyPurgeOnly}&layout={$layout}');
590
  }
591
  }
592
  </script>";
1100
 
1101
  function nitropack_log_purge($url = NULL, $tag = NULL, $reason = NULL) {
1102
  global $np_loggedPurges;
1103
+ if ($tag && is_array($tag)) {
1104
+ foreach ($tag as $tagSingle) {
1105
+ nitropack_log_purge($url, $tagSingle, $reason);
1106
+ }
1107
+ return;
1108
+ }
1109
 
1110
  $keyBase = "";
1111
  if ($url) {
1113
  }
1114
 
1115
  if ($tag) {
1116
+ $tag = nitropack_filter_tag($tag);
1117
+ $keyBase .= $tag;
 
 
 
 
 
 
 
 
 
1118
  }
1119
 
1120
  $purgeRequestKey = md5($keyBase);
1121
+ if (array_key_exists($purgeRequestKey, $np_loggedPurges)) {
1122
+ $np_loggedPurges[$purgeRequestKey]["reason"] = $reason;
1123
+ $np_loggedPurges[$purgeRequestKey]["priority"]++;
1124
+ } else {
1125
+ $np_loggedPurges[$purgeRequestKey] = array(
1126
+ "url" => $url,
1127
+ "tag" => $tag,
1128
+ "reason" => $reason,
1129
+ "priority" => 1
1130
+ );
1131
+ }
1132
  }
1133
 
1134
  function nitropack_invalidate($url = NULL, $tag = NULL, $reason = NULL) {
1147
 
1148
  function nitropack_log_invalidate($url = NULL, $tag = NULL, $reason = NULL) {
1149
  global $np_loggedInvalidations;
1150
+ if ($tag && is_array($tag)) {
1151
+ foreach ($tag as $tagSingle) {
1152
+ nitropack_log_invalidate($url, $tagSingle, $reason);
1153
+ }
1154
+ }
1155
 
1156
  $keyBase = "";
1157
  if ($url) {
1159
  }
1160
 
1161
  if ($tag) {
1162
+ $tag = nitropack_filter_tag($tag);
1163
+ $keyBase .= $tag;
 
 
 
 
 
1164
  }
1165
 
1166
+ $invalidateRequestKey = md5($keyBase);
1167
+ if (array_key_exists($invalidateRequestKey, $np_loggedInvalidations)) {
1168
+ $np_loggedInvalidations[$invalidateRequestKey]["reason"] = $reason;
1169
+ $np_loggedInvalidations[$invalidateRequestKey]["priority"]++;
1170
+ } else {
1171
+ $np_loggedInvalidations[$invalidateRequestKey] = array(
1172
+ "url" => $url,
1173
+ "tag" => $tag,
1174
+ "reason" => $reason,
1175
+ "priority" => 1
1176
+ );
1177
  }
1178
+ }
1179
 
1180
+ function nitropack_queue_sort($a, $b) {
1181
+ if ($a["priority"] == $b["priority"]) {
1182
+ return 0;
1183
+ }
1184
+ return ($a["priority"] < $b["priority"]) ? -1 : 1;
 
1185
  }
1186
 
1187
  function nitropack_execute_purges() {
1188
  global $np_loggedPurges;
1189
  if (!empty($np_loggedPurges)) {
1190
+ uasort($np_loggedPurges, "nitropack_queue_sort");
1191
  foreach ($np_loggedPurges as $requestKey => $data) {
1192
  nitropack_sdk_purge($data["url"], $data["tag"], $data["reason"]);
1193
  }
1197
  function nitropack_execute_invalidations() {
1198
  global $np_loggedInvalidations;
1199
  if (!empty($np_loggedInvalidations)) {
1200
+ uasort($np_loggedInvalidations, "nitropack_queue_sort");
1201
  foreach ($np_loggedInvalidations as $requestKey => $data) {
1202
  nitropack_sdk_invalidate($data["url"], $data["tag"], $data["reason"]);
1203
  }
1622
  // - a request may seem cachable at first, but be determined uncachable during runtime (example: visit to a URL of a page whose post type does not match the enabled cacheable post types, or a cart, checkout page, etc.)
1623
 
1624
  if ((null !== $nitro = get_nitropack_sdk())) {
1625
+ $siteConfig = nitropack_get_site_config();
1626
+ if ($siteConfig && !empty($siteConfig["isDlmActive"]) && !empty($siteConfig["dlm_downloading_url"]) && !empty($siteConfig["dlm_download_endpoint"])) {
1627
+ $currentUrl = $nitro->getUrl();
1628
+ if (strpos($currentUrl, $siteConfig["dlm_downloading_url"]) !== false || strpos($currentUrl, $siteConfig["dlm_download_endpoint"]) !== false) {
1629
+ // Do not modify the nonce times on pages of Download Monitor
1630
+ return $life;
1631
+ }
1632
+ }
1633
  $cacheExpiration = $nitro->getConfig()->PageCache->ExpireTime;
1634
  return $cacheExpiration > $life ? $cacheExpiration : $life; // Extend the life of cacheable nonces up to the cache expiration time if needed
1635
  }
2043
  "alwaysBuffer" => $alwaysBuffer,
2044
  "isEzoicActive" => nitropack_is_ezoic_active(),
2045
  "isNginxHelperActive" => nitropack_is_nginx_helper_active(),
2046
+ "isDlmActive" => nitropack_is_dlm_active(),
2047
+ "dlm_downloading_url" => nitropack_is_dlm_active() ? nitropack_dlm_downloading_url() : NULL,
2048
+ "dlm_download_endpoint" => nitropack_is_dlm_active() ? nitropack_dlm_download_endpoint() : NULL,
2049
  "pluginVersion" => NITROPACK_VERSION
2050
  );
2051
  return nitropack_set_config($staticConfig);
2466
  } else {
2467
  if (
2468
  (!array_key_exists("isEzoicActive", $siteConfig) || $siteConfig["isEzoicActive"] !== nitropack_is_ezoic_active()) ||
2469
+ (!array_key_exists("isNginxHelperActive", $siteConfig) || $siteConfig["isNginxHelperActive"] !== nitropack_is_nginx_helper_active()) ||
2470
+ (!array_key_exists("isDlmActive", $siteConfig) || $siteConfig["isDlmActive"] !== nitropack_is_dlm_active())
2471
  ) {
2472
  if (!nitropack_update_current_blog_config($siteId, $siteSecret, $blogId)) {
2473
  $errors[] = "The NitroPack static config file cannot be updated. Please make sure that the /wp-content/nitropack/ directory is writable and refresh this page.";
integrations.php CHANGED
@@ -333,3 +333,18 @@ function nitropack_ezoic_home_url($url) {
333
 
334
  return $url;
335
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
333
 
334
  return $url;
335
  }
336
+
337
+ // Download Manager integration
338
+ function nitropack_is_dlm_active() {
339
+ return defined('DLM_VERSION');
340
+ }
341
+
342
+ function nitropack_dlm_downloading_url() {
343
+ $downloadingPage = get_option("dlm_dp_downloading_page");
344
+ return $downloadingPage ? get_permalink($downloadingPage) : NULL;
345
+ }
346
+
347
+ function nitropack_dlm_download_endpoint() {
348
+ $downloadEndpoint = get_option("dlm_download_endpoint");
349
+ return $downloadEndpoint ? nitropack_trailingslashit(get_home_url()) . $downloadEndpoint : NULL;
350
+ }
main.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: NitroPack
4
  Plugin URI: https://nitropack.io/platform/wordpress
5
  Description: Everything you need for a fast website. Simple set up, easy to use, awesome support. Caching, Lazy Loading, Minification, Defer CSS/JS, CDN and more!
6
- Version: 1.4.0
7
  Author: NitroPack LLC
8
  Author URI: https://nitropack.io/
9
  License: GPL2
3
  Plugin Name: NitroPack
4
  Plugin URI: https://nitropack.io/platform/wordpress
5
  Description: Everything you need for a fast website. Simple set up, easy to use, awesome support. Caching, Lazy Loading, Minification, Defer CSS/JS, CDN and more!
6
+ Version: 1.4.1
7
  Author: NitroPack LLC
8
  Author URI: https://nitropack.io/
9
  License: GPL2
nitropack-sdk/vendor/composer/InstalledVersions.php CHANGED
@@ -1,5 +1,15 @@
1
  <?php
2
 
 
 
 
 
 
 
 
 
 
 
3
  namespace Composer;
4
 
5
  use Composer\Semver\VersionParser;
@@ -32,7 +42,7 @@ private static $installed = array (
32
  array (
33
  0 => '9999999-dev',
34
  ),
35
- 'reference' => 'b1e792a4e99279d5c5b12cb0a35921d90f0043c2',
36
  ),
37
  'nitropack/nitropackcloud-sdk' =>
38
  array (
1
  <?php
2
 
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
  namespace Composer;
14
 
15
  use Composer\Semver\VersionParser;
42
  array (
43
  0 => '9999999-dev',
44
  ),
45
+ 'reference' => '2322728997a9a3e7f4adbb41229b347cce2ebab0',
46
  ),
47
  'nitropack/nitropackcloud-sdk' =>
48
  array (
nitropack-sdk/vendor/composer/autoload_psr4.php CHANGED
@@ -7,5 +7,5 @@ $baseDir = dirname($vendorDir);
7
 
8
  return array(
9
  'NitroPack\\SDK\\' => array($baseDir . '/NitroPack/SDK'),
10
- 'NitroPack\\' => array($vendorDir . '/nitropack/url/src', $vendorDir . '/nitropack/httpclient/src'),
11
  );
7
 
8
  return array(
9
  'NitroPack\\SDK\\' => array($baseDir . '/NitroPack/SDK'),
10
+ 'NitroPack\\' => array($vendorDir . '/nitropack/httpclient/src', $vendorDir . '/nitropack/url/src'),
11
  );
nitropack-sdk/vendor/composer/autoload_static.php CHANGED
@@ -21,8 +21,8 @@ class ComposerStaticInit3dcb0cd3b9802939155e959c3c6cfd5d
21
  ),
22
  'NitroPack\\' =>
23
  array (
24
- 0 => __DIR__ . '/..' . '/nitropack/url/src',
25
- 1 => __DIR__ . '/..' . '/nitropack/httpclient/src',
26
  ),
27
  );
28
 
21
  ),
22
  'NitroPack\\' =>
23
  array (
24
+ 0 => __DIR__ . '/..' . '/nitropack/httpclient/src',
25
+ 1 => __DIR__ . '/..' . '/nitropack/url/src',
26
  ),
27
  );
28
 
nitropack-sdk/vendor/composer/installed.json CHANGED
@@ -6,19 +6,13 @@
6
  "version_normalized": "dev-master",
7
  "source": {
8
  "type": "git",
9
- "url": "https://bitbucket.org/nitropack/httpclient.git",
10
- "reference": "b1e792a4e99279d5c5b12cb0a35921d90f0043c2"
11
- },
12
- "dist": {
13
- "type": "zip",
14
- "url": "https://bitbucket.org/nitropack/httpclient/get/b1e792a4e99279d5c5b12cb0a35921d90f0043c2.zip",
15
- "reference": "b1e792a4e99279d5c5b12cb0a35921d90f0043c2",
16
- "shasum": ""
17
  },
18
  "require": {
19
  "nitropack/url": "dev-master"
20
  },
21
- "time": "2020-11-04T09:25:18+00:00",
22
  "default-branch": true,
23
  "type": "library",
24
  "installation-source": "source",
@@ -33,17 +27,12 @@
33
  }
34
  ],
35
  "description": "HttpClient library written in PHP, without relying on cURL nor url_fopen",
36
- "homepage": "https://bitbucket.org/nitropack/httpclient",
37
  "keywords": [
38
  "client",
39
  "http",
40
  "library",
41
  "php"
42
  ],
43
- "support": {
44
- "source": "https://bitbucket.org/nitropack/httpclient/src/b1e792a4e99279d5c5b12cb0a35921d90f0043c2/?at=master",
45
- "issues": "https://bitbucket.org/nitropack/httpclient/issues"
46
- },
47
  "install-path": "../nitropack/httpclient"
48
  },
49
  {
@@ -52,15 +41,9 @@
52
  "version_normalized": "dev-master",
53
  "source": {
54
  "type": "git",
55
- "url": "https://bitbucket.org/nitropack/url.git",
56
  "reference": "d10e616a333f5a5107137f88313c7ceba638c8a0"
57
  },
58
- "dist": {
59
- "type": "zip",
60
- "url": "https://bitbucket.org/nitropack/url/get/d10e616a333f5a5107137f88313c7ceba638c8a0.zip",
61
- "reference": "d10e616a333f5a5107137f88313c7ceba638c8a0",
62
- "shasum": ""
63
- },
64
  "time": "2020-11-04T10:08:34+00:00",
65
  "default-branch": true,
66
  "type": "library",
@@ -76,18 +59,15 @@
76
  }
77
  ],
78
  "description": "URL manipulation library",
79
- "homepage": "https://bitbucket.org/nitropack/url",
80
  "keywords": [
81
  "library",
82
  "manipulation",
83
  "php",
84
  "url"
85
  ],
86
- "support": {
87
- "source": "https://bitbucket.org/nitropack/url/src/d10e616a333f5a5107137f88313c7ceba638c8a0/?at=master"
88
- },
89
  "install-path": "../nitropack/url"
90
  }
91
  ],
92
- "dev": true
 
93
  }
6
  "version_normalized": "dev-master",
7
  "source": {
8
  "type": "git",
9
+ "url": "git@bitbucket.org:nitropack/httpclient.git",
10
+ "reference": "2322728997a9a3e7f4adbb41229b347cce2ebab0"
 
 
 
 
 
 
11
  },
12
  "require": {
13
  "nitropack/url": "dev-master"
14
  },
15
+ "time": "2020-12-30T16:50:03+00:00",
16
  "default-branch": true,
17
  "type": "library",
18
  "installation-source": "source",
27
  }
28
  ],
29
  "description": "HttpClient library written in PHP, without relying on cURL nor url_fopen",
 
30
  "keywords": [
31
  "client",
32
  "http",
33
  "library",
34
  "php"
35
  ],
 
 
 
 
36
  "install-path": "../nitropack/httpclient"
37
  },
38
  {
41
  "version_normalized": "dev-master",
42
  "source": {
43
  "type": "git",
44
+ "url": "git@bitbucket.org:nitropack/url.git",
45
  "reference": "d10e616a333f5a5107137f88313c7ceba638c8a0"
46
  },
 
 
 
 
 
 
47
  "time": "2020-11-04T10:08:34+00:00",
48
  "default-branch": true,
49
  "type": "library",
59
  }
60
  ],
61
  "description": "URL manipulation library",
 
62
  "keywords": [
63
  "library",
64
  "manipulation",
65
  "php",
66
  "url"
67
  ],
 
 
 
68
  "install-path": "../nitropack/url"
69
  }
70
  ],
71
+ "dev": true,
72
+ "dev-package-names": []
73
  }
nitropack-sdk/vendor/composer/installed.php CHANGED
@@ -19,7 +19,7 @@
19
  array (
20
  0 => '9999999-dev',
21
  ),
22
- 'reference' => 'b1e792a4e99279d5c5b12cb0a35921d90f0043c2',
23
  ),
24
  'nitropack/nitropackcloud-sdk' =>
25
  array (
19
  array (
20
  0 => '9999999-dev',
21
  ),
22
+ 'reference' => '2322728997a9a3e7f4adbb41229b347cce2ebab0',
23
  ),
24
  'nitropack/nitropackcloud-sdk' =>
25
  array (
nitropack-sdk/vendor/nitropack/httpclient/src/HttpClient.php CHANGED
@@ -40,6 +40,25 @@ class HttpClient {
40
  }
41
  }
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  public static function _isConnectionValid($sock, $readRemainder = false) {
44
  $isValidStream = is_resource($sock) && get_resource_type($sock) != "Unknown";
45
  if ($isValidStream && $readRemainder) {
@@ -252,6 +271,13 @@ class HttpClient {
252
  self::_disconnect($this->sock);
253
  }
254
 
 
 
 
 
 
 
 
255
  public function setURL($URL, $resetRedirects = true) {
256
  if ($resetRedirects) {
257
  $this->redirects_count = 0;
@@ -1309,6 +1335,8 @@ class HttpClient {
1309
  private function error_sink($errno, $errstr) {}
1310
  }
1311
 
 
 
1312
  class URLException extends Exception {}
1313
  class URLEmptyException extends Exception {}
1314
  class URLInvalidException extends Exception {}
40
  }
41
  }
42
 
43
+ public static function drainConnections() {
44
+ $connectionsCount = 0;
45
+ $connectionsRemovedCount = 0;
46
+ foreach (self::$connections as $key => &$connections) {
47
+ $connectionsCount += count($connections);
48
+ foreach ($connections as $index => $con) {
49
+ if (self::_isConnectionValid($con, true)) {
50
+ $connectionsRemovedCount++;
51
+ self::_disconnect($con);
52
+ }
53
+ array_splice($connections, $index, 1);
54
+ }
55
+
56
+ if (empty($connections)) {
57
+ unset(self::$connections[$key]);
58
+ }
59
+ }
60
+ }
61
+
62
  public static function _isConnectionValid($sock, $readRemainder = false) {
63
  $isValidStream = is_resource($sock) && get_resource_type($sock) != "Unknown";
64
  if ($isValidStream && $readRemainder) {
271
  self::_disconnect($this->sock);
272
  }
273
 
274
+ public function abort() {
275
+ $this->disconnect();
276
+ if (!empty($this->asyncQueue)) {
277
+ $this->asyncQueue = [];
278
+ }
279
+ }
280
+
281
  public function setURL($URL, $resetRedirects = true) {
282
  if ($resetRedirects) {
283
  $this->redirects_count = 0;
1335
  private function error_sink($errno, $errstr) {}
1336
  }
1337
 
1338
+ register_shutdown_function(array("\NitroPack\HttpClient", "drainConnections"));
1339
+
1340
  class URLException extends Exception {}
1341
  class URLEmptyException extends Exception {}
1342
  class URLInvalidException extends Exception {}
nitropack-sdk/vendor/nitropack/httpclient/src/HttpClientMulti.php CHANGED
@@ -8,6 +8,7 @@ class HttpClientMulti {
8
  private $errorCallback;
9
  private $returnClients;
10
  private $intervals;
 
11
 
12
  public function __construct() {
13
  $this->clients = array();
@@ -15,6 +16,7 @@ class HttpClientMulti {
15
  $this->successCallback = NULL;
16
  $this->errorCallback = NULL;
17
  $this->returnClients = true;
 
18
  }
19
 
20
  public function returnClients($status) {
@@ -23,6 +25,7 @@ class HttpClientMulti {
23
 
24
  public function push($client) {
25
  $this->clients[] = $client;
 
26
  }
27
 
28
  public function getClients() {
@@ -171,8 +174,35 @@ class HttpClientMulti {
171
  return [$succeededClients, $failedClients];
172
  }
173
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
174
  private function removeClient($client) {
175
  $index = array_search($client, $this->clients, true);
176
- array_splice($this->clients, $index, 1);
 
 
 
 
 
 
177
  }
178
  }
8
  private $errorCallback;
9
  private $returnClients;
10
  private $intervals;
11
+ private $clientRegistrationTimes;
12
 
13
  public function __construct() {
14
  $this->clients = array();
16
  $this->successCallback = NULL;
17
  $this->errorCallback = NULL;
18
  $this->returnClients = true;
19
+ $this->clientRegistrationTimes = new \SplObjectStorage();
20
  }
21
 
22
  public function returnClients($status) {
25
 
26
  public function push($client) {
27
  $this->clients[] = $client;
28
+ $this->clientRegistrationTimes->attach($client, time());
29
  }
30
 
31
  public function getClients() {
174
  return [$succeededClients, $failedClients];
175
  }
176
 
177
+ public function evictStuckClients($timeout = 300) {
178
+ $evictedClients = [];
179
+ $now = time();
180
+ foreach ($this->clients as $client) {
181
+ try {
182
+ $clientRegistrationTime = $this->clientRegistrationTimes->offsetGet($client);
183
+ } catch (\UnexpectedValueException $e) {
184
+ $clientRegistrationTime = 0;
185
+ // Weird client - remove it
186
+ }
187
+
188
+ if ($now - $clientRegistrationTime >= $timeout) {
189
+ $evictedClients[] = $client;
190
+ $client->abort();
191
+ $this->removeClient($client);
192
+ }
193
+ }
194
+
195
+ return $evictedClients;
196
+ }
197
+
198
  private function removeClient($client) {
199
  $index = array_search($client, $this->clients, true);
200
+ if ($index !== false) { // Index can be false if the client has been evicted earlier
201
+ array_splice($this->clients, $index, 1);
202
+ }
203
+
204
+ if ($this->clientRegistrationTimes->offsetExists($client)) { // Offset may not exist if the client has been evicted earlier
205
+ $this->clientRegistrationTimes->detach($client);
206
+ }
207
  }
208
  }
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: cache,perfomance,optimize,pagespeed,lazy load,cdn,critical css,compression
4
  Requires at least: 4.7
5
  Tested up to: 5.5
6
  Requires PHP: 5.3
7
- Stable tag: 1.4.0
8
  License: GNU General Public License, version 2
9
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -169,6 +169,10 @@ No. We’ve designed NitroPack to be a very lightweight solution that adds no CP
169
 
170
  == Changelog ==
171
 
 
 
 
 
172
  = 1.4.0 =
173
  * New feature: Extended WP-CLI compatibility with ability to purge/invalidate by URL or tag
174
  * New feature: Add a method for dynamically preventing automated purge/invalidate
4
  Requires at least: 4.7
5
  Tested up to: 5.5
6
  Requires PHP: 5.3
7
+ Stable tag: 1.4.1
8
  License: GNU General Public License, version 2
9
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
10
 
169
 
170
  == Changelog ==
171
 
172
+ = 1.4.1 =
173
+ * Improvement: Performance improvements in content updates
174
+ * Improvement: Better compatibility with Download Monitor
175
+
176
  = 1.4.0 =
177
  * New feature: Extended WP-CLI compatibility with ability to purge/invalidate by URL or tag
178
  * New feature: Add a method for dynamically preventing automated purge/invalidate