Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: test if gzip extension is available #308

Merged
merged 1 commit into from
Oct 10, 2024
Merged

fix: test if gzip extension is available #308

merged 1 commit into from
Oct 10, 2024

Conversation

stklcode
Copy link
Contributor

@stklcode stklcode commented Oct 6, 2024

If zlib PHP extension is not loaded and there is no substitute in place, gzencode() does not exist and generation of compressed files will fail.

Add a simple function_exists() test to prevent this.

@stklcode stklcode self-assigned this Oct 6, 2024
@stklcode stklcode added the bug label Oct 6, 2024
stklcode added a commit that referenced this pull request Oct 6, 2024
If "gzip" PHP extension is not loaded and there is no substitute in
place, gzencode() does not exist and generation of compressed files will
fail.
Add a simple function_exists() test to prevent this.
@stklcode stklcode changed the title fix: test if gzip extension is available (#308) fix: test if gzip extension is available Oct 6, 2024
stklcode added a commit that referenced this pull request Oct 6, 2024
If "gzip" PHP extension is not loaded and there is no substitute in
place, gzencode() does not exist and generation of compressed files will
fail.
Add a simple function_exists() test to prevent this.
stklcode added a commit that referenced this pull request Oct 6, 2024
If zlib PHP extension is not loaded and there is no substitute in
place, gzencode() does not exist and generation of compressed files will
fail.
Add a simple function_exists() test to prevent this.
@stklcode
Copy link
Contributor Author

stklcode commented Oct 6, 2024

It might seem little far fetched, but providing the function_exists result as default filter parameter allows to implement some logic to define this function on demand, e.g.

add_filter( 'cachify_create_gzip_files', function ( $available ) {
  if ( ! $available ) {
    // Define or load anything that implements gzencode.
    function gzencode( $data, $level ) {
      return $data;
    }
  }

  return true;
} );

Copy link
Member

@Zodiac1978 Zodiac1978 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

Just one thing: it would still be possible to use the filter although gzencode is not available, or not? I know this would be the problem of the one using the filter, but we could also safeguard this. What do you think?

@stklcode
Copy link
Contributor Author

stklcode commented Oct 6, 2024

In the current suggestion: Yes, you can still override the false with a filter, if gzencode is not available.

One might polyfill another compression routine on demand in the filter hook (see example above). Seems more of a theoretical possibility though.

But I'd be fine changing the logic again, so the filter is completely omitted if gzencode is not available. No hard preference for either way.

stklcode added a commit that referenced this pull request Oct 6, 2024
If zlib PHP extension is not loaded and there is no substitute in
place, gzencode() does not exist and generation of compressed files will
fail.
Add a simple function_exists() test to prevent this.
If zlib PHP extension is not loaded and there is no substitute in
place, gzencode() does not exist and generation of compressed files will
fail.
Add a simple function_exists() test to prevent this.
stklcode added a commit that referenced this pull request Oct 6, 2024
If zlib PHP extension is not loaded and there is no substitute in
place, gzencode() does not exist and generation of compressed files will
fail.
Add a simple function_exists() test to prevent this.
@stklcode
Copy link
Contributor Author

stklcode commented Oct 6, 2024

I changed the logic, so if gzencode is not available we disable the feature and do not execute the filter.

This is trivial to change again, but >99.9% should not need such tricky configurations.

@stklcode stklcode added this to the 2.4.0 milestone Oct 6, 2024
Copy link

sonarqubecloud bot commented Oct 8, 2024

@stklcode stklcode merged commit e9684e2 into develop Oct 10, 2024
15 checks passed
@stklcode stklcode deleted the fix/test-gzip branch October 10, 2024 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants