ID: 32806 Comment by: scottij at arbor dot net Reported By: peoned at yahoo dot com Status: No Feedback Bug Type: Performance problem Operating System: Linux PHP Version: 5.0.4 Assigned To: wez New Comment:
I'm getting similar behavior with php 5.2.1. I am reading about 5,000 lines over a tcp socket to another program on the localhost (NOT over a network). Initially, it takes about 500 us per line of text (where the lines are < 20 characters long). Here is the code snippet and output: while (/* some eof and timeout checks here */) { $rstart = microtime(TRUE); $str = fgets($this->dataSocket, 8096); $rstop = microtime(TRUE); $rdiff = $rstop - $rstart; print("read took $rdiff secs.<br>\n"); print("str = $str<br>\n"); } This yields, for example: str = 16549|Item2250||3|2| read took 0.00049185752868652 secs. str = 16550|Item2251||3|2| read took 0.00049495697021484 secs. str = 16551|Blob2252||3|2| read took 0.00049018859863281 secs. I run that over a full dump of my text (5000 lines). If I then close the socket, open a new one, and do the same operation, about halfway through the fgets() times start increasing dramatically: str = 16645|Item2346||3|2| read took 0.0019731521606445 secs. str = 16646|Item2347||3|2| read took 0.0019690990447998 secs. str = 16647|Item2348||3|2| read took 0.0020229816436768 secs. 2 ms to read each short line?? Again, this is just over a local socket, nothing over the network. This is reproducible every time on my system. Thanks. Previous Comments: ------------------------------------------------------------------------ [2005-11-11 01:00:23] php-bugs at lists dot php dot net No feedback was provided for this bug for over a week, so it is being suspended automatically. If you are able to provide the information that was originally requested, please do so and change the status of the bug back to "Open". ------------------------------------------------------------------------ [2005-11-03 22:45:44] [EMAIL PROTECTED] Please try using this CVS snapshot: http://snaps.php.net/php5-latest.tar.gz For Windows: http://snaps.php.net/win32/php5-win32-latest.zip ------------------------------------------------------------------------ [2005-05-04 23:24:07] peoned at yahoo dot com without fwrite() it is significantly faster, gives about 5-6 seconds. But in Perl without print OUT $_; it gives around 1-2 seconds. So it is still slower in PHP because of fgets(). ------------------------------------------------------------------------ [2005-05-02 14:25:11] [EMAIL PROTECTED] Can you try your tests with the fwrite() line commented out? ------------------------------------------------------------------------ [2005-04-28 07:30:31] peoned at yahoo dot com I did an `echo strlen($line).",";` Here are the lengths for some of the first few lines: 42,7,18,11,71,13,8,7,42,7,20,11,73,70,68,63,13,8,7 It looks pretty much like this for the rest of the file. Lines between 1 and 100 chars in length. Note: It isn't the start up cost for sure because I measured the time just around the while loop with the same results. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/32806 -- Edit this bug report at http://bugs.php.net/?id=32806&edit=1