mb_stripos巨大的时差



嗨,我正在进行全文搜索,在我的函数中,我找到了字符串位置(对于字符串出现前后的剪切 x 个字符(,我正在使用 php 函数mb_stripos()。每个请求调用 while(代码波纹管(几次。字符串长度为 500 - 100 000 个字符。

但问题是,在桌面上需要这个时间(每个请求调用几次(cca 500ms,但在服务器上需要 20 000ms。

  • 98% 的请求时间存储在一个字符串上,长 100 000 个字符
  • 通过回波microtime()测量
  • 桌面有 PHP 7.0.9 和 Win7 操作系统和服务器 7.1.3-3+0~20170325135815.21+Jessie~1.gbpafff68 与 Linux 操作系统
  • 两种 Apache (桌面或服务器(都具有 PHP 加速和 OPcache
  • 它在Symfony FW上(可能无关紧要(
  • 大多数PHP操作在服务器上的速度更快

    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);
    }
    

为什么会有如此可怕的差异?

所以问题解决了:缺少库mbstring

使用 php 7.1.x 时的解决方案:apt-get install php7.1-mbstring

在我们的情况下,有一些错误,因此:

apt-get update之后apt-get install php7.1-mbstring并重新启动 Apache 。

最新更新