php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22308 passthru is extremely slow
Submitted: 2003-02-19 16:55 UTC Modified: 2003-02-19 18:35 UTC
From: uk at dataway dot ch Assigned:
Status: Closed Package: Performance problem
PHP Version: 4.3.0 OS: Linux 2.2.18
Private report: No CVE-ID:
 [2003-02-19 16:55 UTC] uk at dataway dot ch
Using passthru("whatever") is almost 100 times slower than doing the equivalent $out = `whatever`;echo $out

I tested this using the following program (I use dd here to generate the data, but the same results appear with any command, cat /etc/passwd etc.)

<?php
        echo "<!--";
        $start = microtime();
        passthru("dd if=/dev/zero count=100");
        $end = microtime();
        echo "-->";

        $mt = explode(' ', $start);
        $mts = $mt[1] + $mt[0];
        $mt = explode(' ', $end);
        $mte = $mt[1] + $mt[0];
        printf("%.3f seconds elapsed (passthru)<p>", $mte - $mts);

        echo "<!--";
        $start = microtime();
        $out = `dd if=/dev/zero count=100`;
        echo $out;
        $end = microtime();
        echo "-->";

        $mt = explode(' ', $start);
        $mts = $mt[1] + $mt[0];
        $mt = explode(' ', $end);
        $mte = $mt[1] + $mt[0];
        printf("%.3f seconds elapsed (backquotes)<p>", $mte - $mts);
?>

On my machine (Pentium 400) this script outputs:

16.231 seconds elapsed (passthru)
0.266 seconds elapsed (backquotes)

Quite a difference, I think.

Compiled with:

./configure \
        --bindir=/usr/local/apache/bin \
        --libdir=/usr/local/apache/php/lib \
        --with-apxs=/usr/local/apache/bin/apxs \
        --with-config-file-path=/usr/local/apache/conf \
        --with-exec-dir=/usr/local/apache/php/bin \
        --with-pear=/usr/local/apache/php/lib \
        --enable-safe-mode \
        --with-openssl=/usr/local/ssl \
        --with-imap=shared,/usr/local \
        --enable-dbx=shared \
        --enable-dio=shared \
        --enable-ftp \
        --with-sybase-ct=shared,/usr/local \
        --with-mysql=shared,/usr/local/mysql \
        --with-pgsql=shared,/usr/local/pgsql \
        --with-gdbm=shared \
        --with-zlib=/usr/local \
        --with-gd=shared \
        --enable-exif=shared \
        --enable-ctype \
        --with-gettext \
        --with-xml=shared \
        --with-expat-dir=/usr/local \
        --enable-xslt=shared \
        --with-xslt-sablot=/usr/local \
        --enable-sockets=shared \
        --enable-wddx=shared \
        --enable-shmop=shared \
        --enable-sysvmsg=shared \
        --enable-sysvsem=shared \
        --enable-sysvshm=shared

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-02-19 18:35 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.


 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Thu Apr 17 06:02:13 2014 UTC