From: uk at dataway dot ch
Operating system: Linux 2.2.18
PHP version: 4.3.0
PHP Bug Type: Performance problem
Bug description: passthru is extremely slow
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
--
Edit bug report at http://bugs.php.net/?id=22308&edit=1
--
Try a CVS snapshot: http://bugs.php.net/fix.php?id=22308&r=trysnapshot
Fixed in CVS: http://bugs.php.net/fix.php?id=22308&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=22308&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=22308&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=22308&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=22308&r=support
Expected behavior: http://bugs.php.net/fix.php?id=22308&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=22308&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=22308&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=22308&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=22308&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=22308&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=22308&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=22308&r=gnused