ID: 19722 Updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] -Status: Open +Status: Analyzed Bug Type: Sockets related Operating System: FreeBSD 4.4 PHP Version: 4CVS-2002-10-02 -Assigned To: +Assigned To: wez New Comment:
fgets should use either a chunk size of 1 or activate non-blocking mode (should give better performance) for socket streams. Previous Comments: ------------------------------------------------------------------------ [2002-10-02 12:59:54] [EMAIL PROTECTED] fgets() is taking a VERY long time to return anything with php from cvs (4.3.0-dev). Here is a test script to show the behavior: <?php function getmicrotime() { list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } $a = getmicrotime(); $fp = fsockopen('mail.haught.org', 25, $errno, $errstr); $b = getmicrotime(); echo "(Connected in " .($b-$a). " seconds)<br>"; echo '>' .fgets($fp, 2048); $c = getmicrotime(); echo " (Read took " .($c-$b). " seconds)<br>"; echo '< EHLO localhost'; fwrite($fp, "EHLO localhost\r\n"); $d = getmicrotime(); echo " (Write took " .($d-$c). " seconds)<br>"; $numlines = 2; //number of lines to read for ($i; $i<$numlines; $i++) { echo '>' .fgets($fp, 2048); $e = getmicrotime(); echo " (Read took " .($e-$d). " seconds)<br>"; } ?> The Results: Sept 22nd tree (Connected in 0.0027800798416138 seconds) >220 haught.org ESMTP (Read took 0.0082589387893677 seconds) < EHLO localhost (Write took 0.00019896030426025 seconds) >250-haught.org (Read took 0.0012670755386353 seconds) >250-AUTH LOGIN CRAM-MD5 PLAIN (Read took 0.0014160871505737 seconds) Sept 23rd tree (Connected in 0.0024210214614868 seconds) >220 haught.org ESMTP (Read took 60.012040019035 seconds) < EHLO localhost (Write took 0.00059795379638672 seconds) >250-haught.org (Read took 60.009819984436 seconds) >250-AUTH LOGIN CRAM-MD5 PLAIN (Read took 120.02024698257 seconds) Oct 2nd tree (Connected in 0.010542035102844 seconds) >220 haught.org ESMTP (Read took 60.008027911186 seconds) < EHLO localhost (Write took 0.00064098834991455 seconds) >250-haught.org (Read took 60.009781002998 seconds) >250-AUTH LOGIN CRAM-MD5 PLAIN (Read took 120.02020800114 seconds) I have tried other mail servers with the same result. All trees compiled with the same configure script. I first noticed this using PEAR's Mail scripts using smtp. configure script: './configure' \ '--enable-posix' \ '--enable-session' \ '--enable-xml' \ '--enable-inline-optimization' \ '--with-apxs=/home/www/sbin/apxs' \ '--with-config-file-path=/etc' \ '--enable-versioning' \ '--with-regex=system' \ '--enable-track-vars' \ '--with-zlib' \ '--with-gd=/usr/local' \ '--with-pgsql=/usr/local' \ '--with-openssl=/usr' \ '--with-xml=/usr/local' \ '--with-expat-dir=/usr/local' \ '--enable-trans-sid' \ '--with-jpeg-dir=/usr/local' \ '--with-png-dir=/usr/local' \ '--with-freetype-dir=/usr/local' \ '--prefix=/home/www' \ '--enable-gd-native-ttf' \ '--with-pcre-regex' \ '--disable-tokenizer' \ '--disable-ctype' \ '--disable-mbstring' \ '--disable-mbregex' \ '--without-mysql' Matt ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=19722&edit=1