avoid mmap overhead for small files
authorSascha Schumann <sas@php.net>
Sat, 11 Sep 1999 18:38:34 +0000 (18:38 +0000)
committerSascha Schumann <sas@php.net>
Sat, 11 Sep 1999 18:38:34 +0000 (18:38 +0000)
ext/standard/file.c

index 5f46697d6dc10c5effc27424457f9ee2cd8443d7..b18d7429707b4cae4934541bc83eaad04c2cb3d9 100644 (file)
@@ -1220,6 +1220,7 @@ static size_t php_passthru_fd(int socketd, FILE *fp, int issock)
 {
        size_t bcount = 0;
        int ready = 0;
+       char buf[8192];
        
 #ifdef HAVE_MMAP 
        if(!issock) {
@@ -1230,23 +1231,23 @@ static size_t php_passthru_fd(int socketd, FILE *fp, int issock)
                size_t len;
 
                fd = fileno(fp);
-               off = ftell(fp);
                fstat(fd, &sbuf);
        
-               len = sbuf.st_size - off;
-               
-               p = mmap(0, len, PROT_READ, MAP_PRIVATE, fd, off);
-               if(p!=MAP_FAILED) {
-                       PHPWRITE(p, len);
-                       munmap(p, len);
-                       bcount += len;
-                       ready = 1;
+               if(sbuf.st_size > sizeof(buf)) {
+                       off = ftell(fp);
+                       len = sbuf.st_size - off;
+                       p = mmap(0, len, PROT_READ, MAP_PRIVATE, fd, off);
+                       if(p!=MAP_FAILED) {
+                               PHPWRITE(p, len);
+                               munmap(p, len);
+                               bcount += len;
+                               ready = 1;
+                       }
                }
        }
 #endif
 
        if(!ready) {
-               char buf[8192];
                int b;
 
                while ((b = FP_FREAD(buf, sizeof(buf), socketd, fp, issock)) > 0) {