pluginkollektiv / cachify

Smart but efficient cache solution for WordPress. Use DB, HDD, APC or Memcached for storing your blog pages. Make WordPress faster!
https://wordpress.org/plugins/cachify/
GNU General Public License v2.0
99 stars 31 forks source link

PHP warnings when generating cache key with latest 2.4 snapshot version #275

Closed stklcode closed 1 year ago

stklcode commented 1 year ago

Describe the bug This misbehavior is a regression from #190.

As a side effect the URL parsing routing has been modified: https://github.com/pluginkollektiv/cachify/blob/d89efc317464d1d6df5a264786621e7a039bf465/inc/class-cachify.php#L1014-L1025

https://github.com/pluginkollektiv/cachify/blob/852cbd07aa431f37d68fad8bd01a67c94ec5ddfe/inc/class-cachify.php#L1000-L1011

If the method is called without arguments (which is done when the cache is populated), it raises a PHP warning:

( ! ) Warning: Undefined array key "host" in /var/www/html/wordpress/wp-content/plugins/cachify/inc/class-cachify.php on line 1081

We do set

$url = wp_unslash( $_SERVER['HTTP_HOST'] ) . wp_unslash( $_SERVER['REQUEST_URI'] )

in this case, which is something like wptest01.openshift.local/testpage/. Passing this string to wp_parse_url results in a path-only array [ "path" => "wptest01.openshift.local/testpage/" ], so thehost` member is not available.

The resulting key is fine, because

'https-' . null . 'wptest01.openshift.local/testpage/'

and

'https-' . 'wptest01.openshift.local' . '/testpage/'

are effectively the same. So caching actually works, but throws a warning.

To Reproduce Steps to reproduce the behavior:

  1. Install latest Cachify development version on any compatible WordPress site
  2. Enable the plugin
  3. Enable PHP warnings in the log and/or output
  4. Visit any yet uncached page

Expected behavior The page should be displayed as usual and a cache entry should be generated in the corresponding backend (database, filesystem, ...) without any warnings.

System:

Additional context Enable PHP warnings in log and/or output, e.g. setting define('WP_DEBUG', true);