|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45265 stripos() very slow
Submitted: 2008-06-13 17:44 UTC Modified: 2010-06-20 19:08 UTC
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: marc at phpmyadmin dot net Assigned: pajoye (profile)
Status: Not a bug Package: Performance problem
PHP Version: * OS: win32 only
Private report: No CVE-ID: None
 [2008-06-13 17:44 UTC] marc at phpmyadmin dot net
stripos() is very slow on Windows, about ten times slower than on Linux. 

Reproduce code:
$a = str_repeat('x', 100000);
for ($i = 0; $i < 10000; $i++) {
        $b = stripos($a, 'y');

Expected result:
On Linux it takes about 3 secondes.

Actual result:
On Windows: 30 seconds


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-10 17:01 UTC]
It seems it's a php_strtolower() issue because we have the same problem by replacing stripos to strtolower...

The problem occurs on Windows also with strtolower()...

71 seconds on Windows, 25s on linux...

Reproduce code:
$a = str_repeat('x', 100000);
for ($i = 0; $i < 10000; $i++) {
        $b = strtolower($a);

 [2008-08-10 23:41 UTC]
The problem is that the Windows API does check for the locale while processing the string (isupper, islower used by tolower or toupper).

Using _tolower/_toupper only speed up the functions using it (as fast or faster than linux). But it does not work for non ASCII input.

I have to check is libc does check for locale as well, if not, I will happily use _tolower on windows too.

That being said, it may be used too in zend then. tolower is used *many* times there.
 [2008-08-11 00:15 UTC]
Nice work Pierre but according to MSDN and yourself, _tolower's Windows implementation is clearly faster than tolower but has undefined results if the character is not ASCII... And we can't rely on that... can we?

According to libc, tolower checks the locale too... And _lower on libc is quite different than Windows's since the _tolower() function is identical to tolower() except that c must be an upper-case letter.

 [2008-08-11 00:34 UTC]
And according to _tolower's Windows implentation isn't ANSI.
 [2009-02-11 15:05 UTC] foruns at dan dot mus dot br
I'm running PHP 5.2.6 in a G4 iBook PPC and I'm experiencing extremely low performance using that function. 

I intended to use stripos() inside a loop to retrieve the positions of multiple DIV elements in a HTML page, increasing the offset value accordingly.

But, on a 64kb document, it would take from 0.4sec to 2.5sec to find each "<div" string.

Strpos() would take as little as 0.004sec on the same document.

 [2010-06-20 19:08 UTC]
-Status: Assigned +Status: Bogus
 [2010-06-20 19:08 UTC]
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

After having analyzed the problem, it seems to be the windows implementation that has serious performance problems in comparison to libc. Nothing we can do against that.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 27 18:01:35 2024 UTC