cvs: /php4 configure.in.in /php4/ext/standard file.c

From: Date: Sat, 11 Sep 1999 18:15:40 +0000
Subject: cvs: /php4 configure.in.in /php4/ext/standard file.c
Groups: php.version4 
Request: Send a blank email to php-version4+get-4328@lists.php.net to get a copy of this message
sas Sat Sep 11 14:15:40 1999 EDT Modified files: /php4 configure.in.in /php4/ext/standard file.c Log: optimize fpassthru/readfile to use mmap instead of fread which especially increases speed on large files. Index: php4/configure.in.in diff -u php4/configure.in.in:1.74 php4/configure.in.in:1.75 --- php4/configure.in.in:1.74 Fri Sep 10 19:36:04 1999 +++ php4/configure.in.in Sat Sep 11 14:15:39 1999 @@ -1,4 +1,4 @@ -dnl $Id: configure.in.in,v 1.74 1999/09/10 23:36:04 sas Exp $ -*- sh -*- +dnl $Id: configure.in.in,v 1.75 1999/09/11 18:15:39 sas Exp $ -*- sh -*- dnl Process this file with autoconf to produce a configure script. divert(0) @@ -256,7 +256,7 @@ fi AC_MISSING_FCLOSE_DECL dnl QNX requires unix.h to allow functions in libunix to work properly -AC_CHECK_HEADERS(fcntl.h unistd.h crypt.h sys/file.h memory.h pwd.h grp.h sys/socket.h sys/wait.h syslog.h string.h sys/varargs.h stdarg.h sys/time.h signal.h netinet/in.h dlfcn.h limits.h sys/types.h unix.h arpa/inet.h locale.h sys/select.h sys/statvfs.h sys/statfs.h) +AC_CHECK_HEADERS(fcntl.h unistd.h crypt.h sys/file.h memory.h pwd.h grp.h sys/socket.h sys/wait.h syslog.h string.h sys/varargs.h stdarg.h sys/time.h signal.h netinet/in.h dlfcn.h limits.h sys/types.h unix.h arpa/inet.h locale.h sys/select.h sys/statvfs.h sys/statfs.h sys/mman.h) dnl Checks for typedefs, structures, and compiler characteristics. AC_STRUCT_TM @@ -314,7 +314,7 @@ dnl Checks for library functions. AC_FUNC_VPRINTF -AC_CHECK_FUNCS(memcpy memmove strdup strerror strcasecmp strstr flock lockf putenv tempnam usleep setlocale gettimeofday setvbuf srand48 lrand48 srandom random link symlink regcomp getlogin cuserid vsnprintf snprintf gcvt utime crypt rint setitimer unsetenv strftime setsockopt tzset shutdown inet_aton statvfs statfs) +AC_CHECK_FUNCS(memcpy memmove strdup strerror strcasecmp strstr flock lockf putenv tempnam usleep setlocale gettimeofday setvbuf srand48 lrand48 srandom random link symlink regcomp getlogin cuserid vsnprintf snprintf gcvt utime crypt rint setitimer unsetenv strftime setsockopt tzset shutdown inet_aton statvfs statfs mmap) AC_FUNC_UTIME_NULL AC_FUNC_ALLOCA dnl## OLDLIBS=$LIBS; LIBS="" Index: php4/ext/standard/file.c diff -u php4/ext/standard/file.c:1.26 php4/ext/standard/file.c:1.27 --- php4/ext/standard/file.c:1.26 Sat Sep 4 09:18:56 1999 +++ php4/ext/standard/file.c Sat Sep 11 14:15:39 1999 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.c,v 1.26 1999/09/04 13:18:56 zeev Exp $ */ +/* $Id: file.c,v 1.27 1999/09/11 18:15:39 sas Exp $ */ /* Synced with php3 revision 1.218 1999-06-16 [ssb] */ @@ -56,11 +56,11 @@ # include <sys/time.h> #endif #if WIN32|WINNT -# include <winsock.h> +#include <winsock.h> #else -# include <netinet/in.h> -# include <netdb.h> -# include <arpa/inet.h> +#include <netinet/in.h> +#include <netdb.h> +#include <arpa/inet.h> #endif #include "snprintf.h" #include "fsock.h" @@ -68,13 +68,17 @@ #include "php_globals.h" #ifdef HAVE_SYS_FILE_H -# include <sys/file.h> +#include <sys/file.h> #endif #if MISSING_FCLOSE_DECL extern int fclose(); #endif +#ifdef HAVE_SYS_MMAN_H +#include <sys/mman.h> +#endif + static void _php3_closesocket(int *); #ifndef THREAD_SAFE @@ -1212,16 +1216,56 @@ } /* }}} */ +static size_t php_passthru_fd(int socketd, FILE *fp, int issock) +{ + size_t bcount = 0; + int ready = 0; + +#ifdef HAVE_MMAP + if(!issock) { + int fd; + struct stat sbuf; + off_t off; + void *p; + 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; + } + } +#endif + + if(!ready) { + char buf[8192]; + int b; + + while ((b = FP_FREAD(buf, sizeof(buf), socketd, fp, issock)) > 0) { + PHPWRITE(buf, b); + bcount += b; + } + } + + return bcount; +} /* {{{ proto int readfile(string filename [, int use_include_path]) Output a file or a URL */ PHP_FUNCTION(readfile) { pval *arg1, *arg2; - char buf[8192]; FILE *fp; - int b, size; - int use_include_path = 0; + int size=0; + int use_include_path=0; int issock=0, socketd=0; /* check args */ @@ -1255,10 +1299,8 @@ } RETURN_FALSE; } - size = 0; - while ((b = FP_FREAD(buf, sizeof(buf), socketd, fp, issock)) > 0) { - PHPWRITE(buf, b); - size += b; + if(php3_header()) { + size = php_passthru_fd(socketd, fp, issock); } if (issock) { SOCK_FCLOSE(socketd); @@ -1304,8 +1346,7 @@ { pval *arg1; FILE *fp; - char buf[8192]; - int id, size, b, type; + int id, size, type; int issock=0; int socketd=0, *sock; @@ -1326,10 +1367,7 @@ } size = 0; if (php3_header()) { /* force headers if not already sent */ - while ((b = FP_FREAD(buf, sizeof(buf), socketd, fp, issock)) > 0) { - PHPWRITE(buf,b); - size += b ; - } + size = php_passthru_fd(socketd, fp, issock); } php3_list_delete(id); RETURN_LONG(size);

« previous php.version4 (#4328) next »