Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

improve header validation speed #47

Conversation

mtymek
Copy link
Contributor

@mtymek mtymek commented Jun 4, 2015

Replacing for loop with regular expressions brought visible performance improvement to header validation.

See simple benchmark: https://gist.github.com/mtymek/660b388db0c5b9d63bc0

// 32-126, 128-254 === visible
// 127 === DEL (disallowed)
// 255 === null byte (disallowed)
if (preg_match('/[^\x09\x0a\x0d\x20-\x7E\x80-\xFE]/', $value)) {
Copy link
Member

Choose a reason for hiding this comment

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

extract the regex as static $regex = '....' improve something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't see any difference.

Copy link
Member

Choose a reason for hiding this comment

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

There won't be a difference. PHP's PCRE caches regexen that it encounters, so subsequent matches using the same expressions will not need re-compilation.

@weierophinney weierophinney added this to the 1.0.2 milestone Jun 4, 2015
@weierophinney weierophinney merged commit 298aa9a into zendframework:master Jun 4, 2015
weierophinney added a commit that referenced this pull request Jun 4, 2015
weierophinney added a commit that referenced this pull request Jun 4, 2015
weierophinney added a commit that referenced this pull request Jun 4, 2015
@Maks3w Maks3w mentioned this pull request Jun 4, 2015
@mtymek mtymek deleted the improve_header_security_performance branch January 27, 2016 21:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants