- bin2hex: documentation ( source)
- strncmp: documentation ( source)
- random_bytes: documentation ( source)
<?php
$needle = bin2hex(random_bytes(15));
$shortString = $needle . bin2hex(random_bytes(20));
$longString = bin2hex(random_bytes(500)) . $needle . bin2hex(random_bytes(500));
for ($i = 0; $i < 100000; $i++) {
0 === strncmp($shortString, $needle, strlen($needle));
}
for ($i = 0; $i < 100000; $i++) {
0 === strncmp($longString, $needle, strlen($needle));
}