Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add compression support for PHP Sessions#2473

Merged
michael-grunder merged 3 commits into
phpredis:developfrom
bitactive:session-compression
Apr 8, 2024
Merged

Add compression support for PHP Sessions#2473
michael-grunder merged 3 commits into
phpredis:developfrom
bitactive:session-compression

Conversation

@bitactive

Copy link
Copy Markdown
Contributor

Previously, compression was available for standard data but not for session handling. This update enables the compression of PHP sessions, allowing for more efficient Redis memory usage.

Previously, compression was available for standard data but not for
session handling. This update enables the compression of PHP sessions,
allowing for more efficient Redis memory usage.
@bitactive

Copy link
Copy Markdown
Contributor Author

The failed checks result from an igbinary issue on macOS, not related to this commit

@michael-grunder michael-grunder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks great.

I suppose you could also abstract the redis_compress and redis_uncompress logic that is each done exactly the same way twice into a helper that would return nonzero if the resulting value needs to be freed, but that's a minor nitpick

Comment thread redis_session.c Outdated
Comment thread redis_session.c Outdated
Comment thread redis_session.c Outdated
Comment thread redis_session.c
@bitactive

Copy link
Copy Markdown
Contributor Author

Thank you for your review and suggestions. Could you please check if everything is now fine or if further improvements are needed?

@michael-grunder michael-grunder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry about the ZEND_STRL Windows issue, I knew it confused Windows but had forgotten it in my old age. 😄

If you update the compress/uncompress helpers to always set the out args I'll get this merged.

I'm also happy to write a test for it. The session tests are a bit involved.

Comment thread redis_session.c Outdated
Comment thread redis_session.c Outdated
Comment thread redis_session.c Outdated
Comment thread redis_session.c Outdated
Comment thread redis_session.c Outdated
Comment thread redis_session.c Outdated
Comment on lines +792 to +797
if (session_uncompress_data(redis_sock, resp, resp_len, &compressed_buf, &compressed_len)) { // Try uncompress
*val = zend_string_init(compressed_buf, compressed_len, 0);
efree(compressed_buf); // Free the buffer allocated by redis_uncompress
} else { // Return raw data
*val = zend_string_init(resp, resp_len, 0);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If you change session_compress_data to always set the out arguments and return whether you need to free the char * you can eliminate this if/else and just always use compressed_buf and then conditionally free it based on the return value from session_compress_data.

Comment thread redis_session.c Outdated
@bitactive

Copy link
Copy Markdown
Contributor Author

Thank you for the advice. It should be better now.

@bitactive bitactive force-pushed the session-compression branch from fa44c7a to be8a7be Compare April 8, 2024 17:58
@michael-grunder michael-grunder merged commit da4ab0a into phpredis:develop Apr 8, 2024
@michael-grunder

Copy link
Copy Markdown
Member

Merged, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants