Hi I am working on full text search and in my function where i finding string position (for cut x chars before and after string occur) i am using php function mb_stripos()
. There is while (code bellow) called few times per request. Strings are from 500 - 100 000 chars long.
But problem is, that on desktop takes this while (called few times per request) cca 500ms, but on server it takes 20 000ms.
microtime()
most php operations are on server quicker
while (($lastPos = mb_stripos($content, $searchString, $lastPos)) !== false) {
if($lastPos <= $offset)
$startStr = 0;
else
$startStr = $lastPos - $offset;
$subs[] = mb_substr($content, $startStr, 100);
$lastPos = $lastPos + strlen($searchString);
}
Why so horrible difference?
So problem solved: missing library mbstring
.
Solution when using php 7.1.x: apt-get install php7.1-mbstring
In our situation there was some errors so:
apt-get update
and after that apt-get install php7.1-mbstring
and restart apache.