|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23698 easy to fix "strlen in for loop" causing serious delay in LARGE sites
Submitted: 2003-05-19 08:39 UTC Modified: 2003-05-19 15:46 UTC
From: dholmes at jccc dot net Assigned: ssb (profile)
Status: Closed Package: PEAR related
PHP Version: 4.3.1 OS: RH 8
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: dholmes at jccc dot net
New email:
PHP Version: OS:


 [2003-05-19 08:39 UTC] dholmes at jccc dot net
I recently discovered apd and I ran it up against our site's framework.  Imagine my surprise when I saw that I was hitting strlen 27917 times! It turns out that I heavily use PEAR DB's prepare() functionality.  In the current CVS, the prepare function is:

    function prepare($query)
        $tokens = split("[\&\?\!]", $query);
        $token = 0;
        $types = array();

        for ($i = 0; $i < strlen($query); $i++) {

But if I change it to:

        $length = strlen($query);
        for ($i = 0; $i < $length; $i++) {

I was able to shave almost 2 seconds off of my uncached render times.   

Don't think for a minute that I don't love PEAR::DB.  I appreciate all your hard work and recommend it constantly.

- Dan


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-19 09:40 UTC]
Looks sound to me.
 [2003-05-19 09:59 UTC]
Sure should be changed (hope that he was just talking about changing the for loop line and not the 3 before that).
 [2003-05-19 10:52 UTC] dholmes at jccc dot net
Oh certainly...just the for loop. :-)
 [2003-05-19 15:46 UTC]
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at
In case this was a documentation problem, the fix will show up soon at

In case this was a website problem, the change will show
up on the site and on the mirror sites in short time.
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Sep 17 08:03:36 2021 UTC