1

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.

  • 98% of request time it stock on one string long 100 000 characters
  • measured by echoing microtime()
  • desktop has php 7.0.9 and win7 os and server 7.1.3-3+0~20170325135815.21+jessie~1.gbpafff68 with linux os
  • both apaches (desktop or server) has PHP acceleration and OPcache
  • it is on symfony fw (it will not matter probably)
  • 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?

Lajdák Marek
  • 2,969
  • 8
  • 29
  • 58
  • 1
    Is your server version a very recent one ? I may be mistaken, but I usually do the opposite : a known to be stable version on both server and desktop and eventually in addition more recent versions on desktop for testing and experiments. In your case, maybe the version on your server is not as stable a sthe one on your desktop. Have you tried with the same version on both systems ? The only other thing I see is the systems themselves, maybe something in your code or config screws on Linux. It's hard to guess not knowing if everything else usually works the same at both ends. – Sarkouille Aug 24 '17 at 12:15
  • Now i trying add to app_dev.php (symfony's 'index') loop with mb_stripos() and i have error `Uncaught Error: Call to undefined function mb_stripos() in...` i am total confused... if i add to code `phpinfo()` there is still php ver 7.1.3... how is possible then in controller it works? (but extremly slow) – Lajdák Marek Aug 28 '17 at 15:05
  • 1
    Have you tried reinstalling your apache ? Maybe there is a missng lib somewhere ? – Sarkouille Aug 28 '17 at 15:10
  • 1
    Sadly i haven't permissions to do that but i must ask our admin... I left it as last option... I will ask him. But i don't understand why if i using this function on the same server, same php but in controller function works... (bad but works) – Lajdák Marek Aug 28 '17 at 15:16
  • @ksjohn you was right there was missing (or damaged) library now it works in normal response times (see my answer) – Lajdák Marek Aug 28 '17 at 15:51
  • 1
    Well done ! Don't forget to accept the answer ! :D – Sarkouille Aug 28 '17 at 23:49

1 Answers1

2

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.

Ben Hyde
  • 1,503
  • 12
  • 14
Lajdák Marek
  • 2,969
  • 8
  • 29
  • 58