Skip Menu |

This queue is for tickets about the PHP-Session CPAN distribution.

Report information
The Basics
Id: 47370
Status: new
Priority: 0/
Queue: PHP-Session

People
Owner: Nobody in particular
Requestors: bassilov [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: PHP::Session::Serializer::PHP Hash serialization
One can get a lot of serialized strings for the same Hash because of different order of keys. It will lead to unnecessary session (DB or File) updates. I think you should add an opportunity to sort hash's keys before encoding. This can be added I think; sub encode_hash_sorted { my($self, $value) = @_; my $buffer = ''; my @hsort = sort keys %{$value}; $buffer .= sprintf('a:%d:',scalar(@hsort)) . '{'; for (@hsort) { $buffer .= $self->do_encode($_); $buffer .= $self->do_encode($$value{$_}); } $buffer .= '}'; return $buffer; } Another problem is that arrays are converted to hash before encoding so serialize results are also different for arrays. sub encode_array_sorted { my($self, $value) = @_; my $buffer = ''; $buffer .= sprintf('a:%d:',scalar(@$value)) . '{'; for (my $i=0;$i<scalar(@$value);$i++) { $buffer .= $self->do_encode($i); $buffer .= $self->do_encode($$value[$i]); } $buffer .= '}'; return $buffer; }