php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #73262
Patch streams.c.5.6.20.unfinished.patch revision 2016-10-12 23:26 UTC by jeffreydwalter at gmail dot com

Patch streams.c.5.6.20.unfinished.patch for Performance problem Bug #73262

Patch version 2016-10-12 23:26 UTC

Return to Bug #73262 | Download this patch
Patch Revisions:

Developer: jeffreydwalter@gmail.com

1116c1116
< 	size_t didwrite = 0, towrite, justwrote;
---
>     size_t didwrite = 0, numwrites = 1, towrite, justwrote;
1118,1144c1118,1134
<  	/* if we have a seekable stream we need to ensure that data is written at the
<  	 * current stream->position. This means invalidating the read buffer and then
< 	 * performing a low-level seek */
< 	if (stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0 && stream->readpos != stream->writepos) {
< 		stream->readpos = stream->writepos = 0;
< 
< 		stream->ops->seek(stream, stream->position, SEEK_SET, &stream->position TSRMLS_CC);
< 	}
< 
< 
< 	while (count > 0) {
< 		towrite = count;
< 		if (towrite > stream->chunk_size)
< 			towrite = stream->chunk_size;
< 
< 		justwrote = stream->ops->write(stream, buf, towrite TSRMLS_CC);
< 
< 		/* convert justwrote to an integer, since normally it is unsigned */
< 		if ((int)justwrote > 0) {
< 			buf += justwrote;
< 			count -= justwrote;
< 			didwrite += justwrote;
< 
< 			/* Only screw with the buffer if we can seek, otherwise we lose data
< 			 * buffered from fifos and sockets */
< 			if (stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0) {
< 				stream->position += justwrote;
---
>     /* if we have a seekable stream we need to ensure that data is written at the
>      * current stream->position. This means invalidating the read buffer and then
>      * performing a low-level seek */
>     if (stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0 && stream->readpos != stream->writepos) {
>         stream->readpos = stream->writepos = 0;
>         stream->ops->seek(stream, stream->position, SEEK_SET, &stream->position TSRMLS_CC);
>     }       
> 
>     while (count > 0) {
> 
> 		// If we write more than about 5MB, then increase the buffer to 196K.
> 		if(numwrites%320 == 0) {
> 			if(stream->chunk_size < FG(def_chunk_size) * 24) {
>             	stream->chunk_size = stream->chunk_size * 4;
> #if STREAM_DEBUG
> fprintf(stderr, "Scaling: %d\n", stream->chunk_size);
> #endif
1146,1150c1136
< 		} else {
< 			break;
< 		}
< 	}
< 	return didwrite;
---
>         }
1152c1138,1164
< }
---
>         towrite = count;
>  
>         if (towrite > stream->chunk_size)
>             towrite = stream->chunk_size;          
>         
>         justwrote = stream->ops->write(stream, buf, towrite TSRMLS_CC);
>         
>         numwrites++;
> 
>         /* convert justwrote to an integer, since normally it is unsigned */
>         if ((int)justwrote > 0) {
>             buf += justwrote;
>             count -= justwrote;
>             didwrite += justwrote;
> 
>             /* Only screw with the buffer if we can seek, otherwise we lose data
>              * buffered from fifos and sockets */
>             if (stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0) {
>                 stream->position += justwrote;
>             }
>         } else {
>             break;
>         }
>     }   
>     return didwrite;
> 
> }   
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 19:01:29 2024 UTC