php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16545 parse_url is *slow*
Submitted: 2002-04-11 05:32 UTC Modified: 2002-10-06 11:27 UTC
From: ssb at fast dot no Assigned:
Status: Closed Package: Performance problem
PHP Version: 4.1.2 OS: RedHat 7.2
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ssb at fast dot no
New email:
PHP Version: OS:

 

 [2002-04-11 05:32 UTC] ssb at fast dot no
parse_url() is over 30 times slower than a PHP code doing the same thing with preg_match.  Check this out:

parse_url.php:

<?php

for ($i = 0; $i < 50000; $i++) {
    $fullurl = "http://www.example.com:80/blah/bing?foo=bar&gazonk=true";
    $url = parse_url($fullurl);
}

?>

$ time php parse_url.php 

real	1m41.777s
user	1m35.770s
sys	0m0.200s


preg_match.php:

<?php

for ($i = 0; $i < 50000; $i++) {
    $fullurl = "http://www.example.com:80/blah/bing?foo=bar&gazonk=true";
    preg_match('!^(([^:/?#]+):)?(//([^/:?#]*)(:(\d+))?)?([^?#]*)(\\?([^#]*))?(#(.*))?!', $fullurl, $matches);
    list(,,$url['scheme'],,$url['host'],,$url['port'],$url['path'],,$url['query']) = $matches;
}

?>

$ time php preg_match.php

real	0m2.950s
user	0m2.940s
sys	0m0.000s


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-10-06 11:27 UTC] iliaa@php.net
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 http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

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


 [2019-06-12 17:29 UTC] icarus10149 at gmail dot com
The following:
list(,,$url['scheme'],,$url['host'],,$url['port'],$url['path'],,$url['query'])

Should be:
list(,,$url['scheme'],,$url['host'],,$url['port'],,$url['path'],,$url['query'])

Missing the double comma between $url['port'] and $url['path']
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 02:01:32 2024 UTC