Re: PHP 4.0 Bug #6038: fread() in non blocking mode cant't read more than 901120 bytes

From: Date: Wed, 09 Aug 2000 10:07:38 +0000
Subject: Re: PHP 4.0 Bug #6038: fread() in non blocking mode cant't read more than 901120 bytes
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-28232@lists.php.net to get a copy of this message
* "Stanislav Malyshev" <stas@zend.com> wrote: | >> socket_set_blocking($sock, false); | >> $data = fread($sock, 13453592); | >> print strlen($data); | >> | >> The stream is exactly 13453592 bytes long and can "easily" be read | >> in blocking mode. | >> | >> "easily" means that fread() takes about 4 _minutes_ to read the data | >> where e.g. telnet or other tools needs 4 _seconds_. | | 12M in 4 seconds? You must have a really good network... Yes, a loopback network. | Anyway, are you sure you really need to allocate and store in memory all | those 12 megs? What else should i do? I don't know what anyone wants to do with the data, the function is just there to read the HTTP Response. I modified my function to read little blocks instead of one large block. These are my results: ------------------------------------------------------- Blocking: true Blocksize: 1048576 bytes 1048576 bytes read ( 32.06%). duration: 3.88 seconds 1048576 bytes read ( 64.11%). duration: 12.25 seconds 1048576 bytes read ( 96.17%). duration: 20.87 seconds 1048576 bytes read (100.00%). duration: 3.92 seconds strlen(): 3271003 bytes (100.00%) ------------------------------------------------------- It takes longer and longer and... ------------------------------------------------------- Blocking: false Blocksize: 1048576 bytes 1048576 bytes read ( 32.06%). duration: 1.19 seconds 1048576 bytes read ( 64.11%). duration: 0.09 seconds 1048576 bytes read ( 96.17%). duration: 0.09 seconds 1048576 bytes read (100.00%). duration: -0.88 seconds strlen(): 327680 bytes (10.02%) ------------------------------------------------------- Cool. In non-blocking-mode i lose 90% of my data (they are not transferd, says Apache). I found out that the blocksize must be under 84000 bytes to work in non-blocking mode: ------------------------------------------------------- Blocking: false Blocksize: 83500 bytes 83500 bytes read ( 2.55%). duration: 0.04 seconds 83500 bytes read ( 5.11%). duration: 0.09 seconds [...] 83500 bytes read ( 99.56%). duration: 1.83 seconds 83500 bytes read (100.00%). duration: 1.85 seconds strlen(): 3271003 bytes (100.00%) ------------------------------------------------------- Now lets take a look at really (wow, 13.3 MB) large resource: ------------------------------------------------------- Blocking: true Blocksize: 81920 bytes 81920 bytes read ( 0.61%). duration: 0.25 seconds 81920 bytes read ( 1.22%). duration: 0.09 seconds 81920 bytes read ( 1.83%). duration: 0.08 seconds [...] 81920 bytes read ( 44.45%). duration: 4.32 seconds 81920 bytes read ( 45.06%). duration: 3.45 seconds 81920 bytes read ( 45.67%). duration: 3.51 seconds [...] ------------------------------------------------------- or with larger blocks ------------------------------------------------------- Blocking: true Blocksize: 1048576 bytes 1048576 bytes read ( 7.79%). duration: 2.58 seconds 1048576 bytes read ( 15.59%). duration: 12.66 seconds 1048576 bytes read ( 23.38%). duration: 18.26 seconds 1048576 bytes read ( 31.18%). duration: 24.58 seconds 1048576 bytes read ( 38.97%). duration: 35.79 seconds 1048576 bytes read ( 46.76%). duration: 41.90 seconds [...] ------------------------------------------------------- Other tools for the complete resource: Lynx: < 15 seconds Wget: < 15 seconds Netcat: < 10 seconds LWP::Simple::get(): < 7 seconds And as we are here, i've also tried to read a 100.000.000 bytes resource in one block and i got after 14 minutes: [...] Time: 7:41:51 D:\dev\php\http>php D:\dev\php\http\test_f.php >nul FATAL: erealloc(): Unable to allocate 17645568 bytes Time: 7:54:47 D:\dev\php\http> [...] Yeah, 120 MB free and this is not enough for PHP, or what? 14 minutes by the way, my php.ini says the script should be terminated after 3 minutes but ... yes, it wasn't. regards, -- Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://www.bjoernsworld.de am Badedeich 7 · Telefon: +49(0)4667/981ASK · http://bjoern.hoehrmann.de 25899 Dagebüll · PGP KeyID: 0xA4357E78 · http://learn.to/quote <---

« previous php.dev (#28232) next »