php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #19722 fgets taking a long time to return anything
Submitted: 2002-10-02 12:59 UTC Modified: 2002-10-04 21:30 UTC
From: matt at haught dot com Assigned: wez (profile)
Status: Closed Package: Sockets related
PHP Version: 4CVS-2002-10-02 OS: FreeBSD 4.4
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: matt at haught dot com
New email:
PHP Version: OS:

 

 [2002-10-02 12:59 UTC] matt at haught dot com
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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-10-03 03:25 UTC] wez@php.net
fgets should use either a chunk size of 1 or activate non-blocking mode (should give better performance) for socket streams.
 [2002-10-04 21:30 UTC] sas@php.net
Fixed in CVS. Thanks for your report.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Oct 08 21:01:27 2024 UTC